简体   繁体   English

jQuery在加载特定元素时触发事件

[英]jQuery trigger an event when specific element is loaded

I would like to globally catch whenever some element (fe textarea ) is rendered on the page to do something with it. 每当页面上呈现某些元素(fe textarea )以对其进行处理时,我都希望全局捕获。 Element could be inserted by AJAX request too. 元素也可以由AJAX请求插入。

// This is just an example of functionality I want to achieve
// Not a real code
$(document).on('render', 'textarea', function() {
    $(this).whatEver();
});

I know about document's ajaxComplete method, but I am looking for some more generic way. 我知道文档的ajaxComplete方法,但是我正在寻找一些更通用的方法。

Use: 采用:

$('#container').on('DOMNodeInserted ', 'textarea', function(){
$(this).whatEver();
})

Or: 要么:

$(document).ready(function () {
 //Loaded...
 $('textarea').whatEver();
});

Found the way to do it using livequery plugin which repetitively checks for elements in dom. 找到了使用livequery插件重复执行dom中元素检查的方法。 So I can do following: 因此,我可以执行以下操作:

$('textarea').livequery(function() { $(this).whatEver(); });

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

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