我有一個通過$ .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() - 工作完美。 –