Tinymce html5 placeholder by reading attribute from textarea

前端 未结 8 536
北恋
北恋 2020-12-31 19:41

For standard textareas I use this plugin to create a placeholder. How can I extend tinymce so that this works in this way also.

E.g the default value is read from the

8条回答
  •  别那么骄傲
    2020-12-31 20:33

    The answers above were not working for me, but here's my (for me) working code based on the answers above and using onchange_callback. Hope it helps someone!

    onchange_callback : function(ed){
                var tinymce_placeholder = $('#' + ed.id).attr("placeholder");     
                setTimeout(function () {
                    var content = ed.getContent().replace(/

    |<\/p>/g, ''); if (content == '') { ed.setContent(tinymce_placeholder); } }, 200); }, setup: function (ed) { // Set placeholder var tinymce_placeholder = $('#' + ed.id); if (tinymce_placeholder.length) { ed.onInit.add(function (ed) { var cont = ed.getContent(); if (cont.length == 0) { ed.setContent(tinymce_placeholder.attr("placeholder")); } }); ed.onMouseDown.add(function (ed, e) { var content = ed.getContent().replace(/

    |<\/p>/g, ''); if (content == tinymce_placeholder.attr("placeholder")) { ed.setContent(''); } }); } }

提交回复
热议问题