如何使用jQuery检测到使用jWYSIWYG插件的textarea的内容? [英] How to detect a change with jQuery to the contents of a textarea that's using jWYSIWYG plugin?

查看:132
本文介绍了如何使用jQuery检测到使用jWYSIWYG插件的textarea的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以我的形式在textareas上使用jwysiwyg插件(jwysiwyg: https://github.com/akzhan / jwysiwyg



我想检测到我的形式的任何文本区域的更改。



通常,使用标准的非智能文本区域,我可以这样做:

  $('textarea')。change (e){
alert('Something changed!');
});

由于jwysiwyg的DOM操作,jwysiwyg被使用时,这证明是无效的。



任何人都有任何指针?

解决方案

使用这段代码,我已经用帮助测试了/example/01.basic.html和02.full.html,
我猜也可以和其他人一起工作:

  $(document).ready(function(){
var current = $(#wysiwyg-wysiwyg-iframe)。contents()。find('html');

function detectFn(){
alert('Detected');
}

var timer;

current.bind({
keyup:function(){
clearTimeout(timer);
timer = setTimeout(detectFn,2000)

}
});

});

来源
Yasir Laghari和Ghommey有真正的



jQuery / JavaScript:访问iframe的内容



在按键上,当X秒呼叫功能停止时



说明



1)'jwysiwyg插件'的作用是替换iframe的textarea。文本在p标签内,另一件需要考虑的是该标签无法单击,如果您单击文本,您实际点击的是iframed html标签。



2)对于jQuery访问和选择iframed元素,必须使用'contents()'方法。这样我们可以用iframe开始触发一些功能。



3)创建检测到伪造变化后要使用的代码的detectFn() textarea。



4)声明变量'timer'。



5)bind()方法必须与'iframed html'标签一起使用,用于使用keyup事件。这样可以模拟textarea的打字动作。



6)每个按键都将执行多次检测功能,以防止这种情况,我们使用setTimeout方法和存储变量timer中的detectFn。最后,变量必须作为参数传递给clearTimeout,这样每个keyup都将取消以前执行的detect功能。


I'm using the jwysiwyg plugin on textareas in my form (jwysiwyg: https://github.com/akzhan/jwysiwyg )

I want to detect changes to any of the textareas that are in my form.

Normally, with a standard non-wysiwyg textarea, I do:

$('textarea').change(function(e){
    alert('Something changed!');
 });

This proves ineffective when jwysiwyg is being used due to jwysiwyg's DOM manipulation.

Anyone have any pointers?

解决方案

Use this code, I've tested it with the help/example/01.basic.html and 02.full.html, I guess it will work with the others too:

$(document).ready(function(){
var current = $("#wysiwyg-wysiwyg-iframe").contents().find('html');

     function detectFn(){
          alert('Detected');
       } 

       var timer;

    current.bind({    
                keyup: function(){
                    clearTimeout(timer);
          timer = setTimeout(detectFn, 2000)

                }
    });

});

The sources:
Yasir Laghari and Ghommey have the real credit of this solution.

jQuery/JavaScript: accessing contents of an iframe

On keypress, when stop after X seconds call function

Explanation:

1) The 'jwysiwyg plugin' what it does is to replace the textarea for an iframe. The text is inside a 'p' tag, another thing to consider is that this tag can not be clicked, if you click the text, what you are actually clicking is the 'iframed html' tag.

2) For jQuery to access and select an iframed element, the 'contents()' method must be used. That way we can start triggering some functions with the iframe.

3) Create the detectFn() that will execute the code you want to use after detecting the change in the fake textarea.

4) Declare the variable 'timer'.

5) The bind() method must be used with the 'iframed html' tag for using the keyup event. That way the typing action of a textarea will be simulated.

6) Each keyup will execute the detect function multiple times, to prevent that, we use the setTimeout method and store the detectFn in the variable 'timer'. Finally the variable must be passed to the clearTimeout as an argument, that way each keyup, will cancel the previous execution of the detect function.

这篇关于如何使用jQuery检测到使用jWYSIWYG插件的textarea的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆