简体   繁体   English

活动中? 把它关掉?

[英]On events? Turn it off?

On keyup my script does something, I was wondering if I could turn it off, as in, I only want it to check one key up. 在keyup上,我的脚本会执行某些操作,我想知道是否可以将其关闭,例如,我只希望它检查一个键。

ckEditorNewsArticle.document.on("keyup", function(){

Edit: 编辑:

ckEditorNewsArticle.document.on('keyup', function(){
                      alert('key up');
                });

This works. 这可行。 But I cant get it to fire only once, by using one. 但是我无法使用它来触发一次。

ckEditorNewsArticle.document.one('keyup', function(){
                      alert('one');
                });

You can turn off events using (surprise, surprise), .off() . 您可以使用(惊奇,惊喜) .off() off()关闭事件。

ckEditorNewsArticle.document.off('keyup');

If you want a handler to run only once though, might I suggest using .one() ? 如果您希望处理程序仅运行一次,我是否建议使用.one()

ckEditorNewsArticle.document.one('keyup', function () {
    // do something
});

use .one() : 使用.one()

Attach a handler to an event for the elements. 将处理程序附加到元素的事件。 The handler is executed at most once per element. 该处理程序每​​个元素最多执行一次。

Documentation: http://api.jquery.com/one/ 文档: http : //api.jquery.com/one/

Working example: http://jsfiddle.net/54ymc/ 工作示例: http : //jsfiddle.net/54ymc/

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

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