简体   繁体   English

如何使用查询更改tinymce背景onchange的颜色

[英]How can I change color of tinymce background onchange using query

I have a form with various input fields and if they change I want to change the background color 我有一个带有各种输入字段的表单,如果它们更改,我想更改背景色

I use the following code which does what I need 我用下面的代码做我需要的

$( document ).ready(function() {
    $('textarea, input, select').change(function () {
        $(this).css({ 'background': '#D6FFD6' });
    });
});

The problem comes with one of my fields which is a tinymce field 问题来自我的一个领域,这是一个tinymce领域

This is not affected by my code 这不受我的代码的影响

If I inspect the element of the TinyMCE field the actual data is held in a hidden textarea and the text that shows is in an iframe 如果我检查TinyMCE字段的元素,则实际数据将保存在隐藏的文本区域中,而显示的文本将在iframe中

Is there any way I can change the background on change and if so how 有什么办法可以更改更改背景,如果可以的话,如何

To change the body background color you can use: 要更改主体背景颜色,可以使用:

tinymce.activeEditor.contentDocument.body.style.backgroundColor = '#f0f0f0';

To get the active editor as a jQuery element, just use: 要将活动编辑器作为jQuery元素,只需使用:

$(tinymce.activeEditor)

Edit: 编辑:

You have to handle events separately, because textarea elements are replaced by the editor (this works on v4 version): 您必须分别处理事件,因为textarea元素已被编辑器替换(这在v4版本上有效):

$('textarea, input, select').change(function () {
    $(this).css({ 'background': '#D6FFD6' });
});

tinymce.activeEditor.on('change', function(){
    this.contentDocument.body.style.backgroundColor = '#D6FFD6';
});

Last edit: 最后编辑:

To get it work, you have to register events once window is loaded, like this: 要使其正常工作,必须在window加载后注册事件,如下所示:

// this is for v3
$(window).load(function() { 
    tinyMCE.activeEditor.onChange.add(function(){ this.contentDocument.body.style.backgroundColor = '#D6FFD6' }); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM