我有一个通过$ .load()加载的dom对象。然后我有点击函数连接到被加载的对象。如何获取通过AJAX加载的DOM对象来触发附加到新DOM对象的jQuery
点击函数不会触发新的DOM对象。
我错过了什么?
没有在.cntrls a
点击功能正在发射。
这里有一个例子:
$('.ati a').click(function() {
// First, clear out the current content
if ('.msg-obj' || '.poc-obj' || '.pom-obj || .cntrls') {
$('.msg-obj, .poc-obj, .pom-obj, .cntrls').hide();
};
// Get the URL for the object that is clicked
var clickedObjPath = $(this).attr('href');
console.log(clickedObjPath);
$('#msg').load(clickedObjPath + ' .msg-obj').fadeIn();
$('.poc').load(clickedObjPath + ' .poc-obj').fadeIn();
$('.pom').load(clickedObjPath + ' .pom-obj').fadeIn();
$('.cntrls').load(clickedObjPath + ' .cntrls a').fadeIn();
return false;
});
$('.cntrls a ').click(function() {
// Get the URL for the object that is clicked
var cntrlObjPath = $(this).attr('href');
console.log(cntrlObjPath);
return false;
});
就是这样!谢谢您的帮助。我用.on() - 工作完美。 –