[英]Set Value Inside a TinyMCE Editor using jQuery
嗨,我需要在 tinyMCE 編輯器中設置預定義的內容。 下面是我的 html 和 jquery。
<script type="text/javascript">
tinyMCE.init( {
mode : "exact" ,
elements : "country"
});
</script>
<script type="text/javascript">
$(function() {
$("#lang").change(function() {
var s = $(this).val(); alert(s);
$("#country").val(s);
})
})
</script>
<select id="lang">
<option value="">Please Select country</option>
<option value="us">US</option>
<option value="es">SPAIN</option>
<option value="jp">JAPAN</option>
</select><br /><br />
<textarea id="country" cols="10" rows="5"></textarea>
該腳本適用於普通文本區域,但不適用於 tinyMCE。 我在這方面做錯了什么。
謝謝
我認為你可以這樣做:
$(function() {
$("#lang").change(function() {
var s = $(this).val();
alert(s);
tinyMCE.activeEditor.setContent(s);
});
});
對我來說只有代碼有效:
tinyMCE.get('my_textarea_id').setContent(my_value_to_set);
也許這是新版本 tinyMCE 的代碼! (微型 MCE Api 3)
只是這對我有用
$("#description").val(content);
你也可以試試這個:
不替換 tinymce 內的全部內容,將光標設置在要在 tinymce 內添加值的位置
$(document).on('change','#lang', function() {
var Getname = $(this).val();
if (Getname != '') {
//tinyMCE.activeEditor.setContent(s); // This is for replace all content
tinyMCE.activeEditor.execCommand('mceInsertContent',false,Getname); // Append new value where your Cursor
//console.log(Getname)
}
});
我在TinyMCE 5的新版本中使用此代碼
在ajax調用之前,你需要調用一個觸發器
tinyMCE.trigge*emphasized text*rSave(true, true);
完整語法
tinyMCE.triggerSave(true, true);
$.ajax({
data: $('#userForm').serialize(),
url: "{{ route('versions.store') }}",
type: "POST",
dataType: 'json',
success: function (data) {
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.