富文本編輯器 tinymce 獲取文本內容、設置文本內容


<Tinymce
  id="textAreaContent"
  :options="tinymceOpts"
  v-model="formData.text"
  @change="inputTinymce"
/>


inputTinymce(data) {
    this.textNum = data.target.getContent({"format" : "text"}).length
    this.formData.preface = data.target.getContent({"format" : "text"}).substring(0, 50)
    console.log(this.formData.preface);
    this.formData.text = data.target.getContent()
}

 

1、如果當前頁面只有一個編輯器: 
獲取內容:tinyMCE.activeEditor.getContent() 
設置內容:tinyMCE.activeEditor.setContent(“需要設置的編輯器內容”)

2、如果當前頁面有多個編輯器(下面的“[0]”表示第一個編輯器,以此類推): 
獲取內容:tinyMCE.editors[0].getContent() 
設置內容:tinyMCE.editors[0].setContent(“需要設置的編輯器內容”)

3、獲取不帶HTML標記的純文本內容: 
var activeEditor = tinymce.activeEditor; 
var editBody = activeEditor.getBody(); 
activeEditor.selection.select(editBody); 
var text = activeEditor.selection.getContent( { ‘format’ : ‘text’ } );

取到的 text 即為純文本內容。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM