动态加载内容上的jQuery事件 [英] jquery events on dynamically loaded content
本文介绍了动态加载内容上的jQuery事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在一些动态加载的内容上添加click事件,并且我有这个:
I am trying to add a click event on some dynamically loaded content and I have this:
$("#dailyCount table thead th").each(function(){
var yd = "#" + $(this).attr("id");
$(document).on("click", yd, function(){
alert("a");
});
});
元素ID是从1到当前月份的最后一天.有什么想法吗?
The element id is from 1 to the last day of current month. Any ideas ?
推荐答案
您可以对从选择器返回的所有元素使用一个委托,而不是为每个元素添加委托处理程序.
Instead of add a delegated handler for each element you can use one delegation to all elements returned from your selector.
所以尝试:
$(document).on("click", "#dailyCount table thead th", function(){
alert("a");
});
演示: http://jsfiddle.net/agLBm/
这篇关于动态加载内容上的jQuery事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文