我在文本区域的 onfocus 事件上调用一个函数,它工作正常。但在添加 tinymce 后它停止工作。
这是我的代码
Javascript...
<script src="tinymce/tinymce.min.js" type="text/javascript"></script>
<script type="text/javascript">
tinyMCE.init({
theme: "modern",
mode: "exact",
elements: "txtDescription",
auto_focus: false,
resize: false,
convert_urls: false,
menubar: false,
paste_data_images: true,
plugins: ['advlist autolink lists link image charmap print preview hr anchor pagebreak searchreplace visualblocks visualchars media nonbreaking table contextmenu template paste textcolor'],
toolbar: "bold italic underline charmap subscript superscript table link image media, formulabutton, imagebutton",
height: 150,
width: 600
});
function ShowMessage() {
alert("Hello");
}
</script>
和 HTML...
<div>
<textarea id="txtDescription" onfocus="ShowMessage()"></textarea>
</div>
最佳答案
这里的问题是你的文本区域被 tinymce 隐藏了,只有在必要时 tinymce 才会使用它来将 tinymce 内容写回它。
Tinymce 创建了一个自己的 iframe,使用户可以插入/编辑格式化的内容。您必须将焦点事件绑定(bind)到此 iframe 或更好的 iframe 主体。这是代码:
var my_editor = tinymce.get('my_editor_id'); // or tinymce.editors[0]
$(my_editor.getBody()).bind('focus', function(e){
console.log('Tinymce body iframe has been focused.');
});
或
var my_editor = tinymce.get('my_editor_id'); // or tinymce.editors[0]
my_editor.getBody().addEventListener('focus', function() {
console.log('Tinymce body iframe has been focused.');
});
关于javascript - 添加 tinymce 4 后,textarea 事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245192/