如何在tinymce v4.0中添加占位符

How to add the placeholder in tinymce v4.0

您好,有没有办法为 tinymce v4.0 添加占位符?我在 tinymce 中需要 html 5 个占位符实现,但默认情况下不存在。

 <textarea id="Text" placeholder="Create your prompt here." ui-tinymce="$ctrl.tinymceOptions" ng-model="$ctrl.tmcModel"></textarea>

这对我有用。

 var iframe = document.getElementsByTagName('iframe')[0];
     iframe.style.resize = 'vertical';

假设一个人正在使用 tinyMCE 4,您可以在初始化时添加一个占位符,然后在焦点上将其删除。请记住 TinyMCE 使用 iframe。 需要改进以提高效率,但这里有一个快速的方法:

tinymce.init({
  //here all the rest of the options
  //xxxxx
  //Add the placeholder
  setup: function (editor) {
    editor.on('init', function(){
      if (tinymce.get('Text').getContent() == ''){
        tinymce.get('Text').setContent("<p id='#imThePlaceholder'>Your nice text here!</p>");
      }
    },
    //and remove it on focus
    editor.on('focus',function(){
      $('iframe').contents().find('#imThePlaceholder').remove();
    }),
})