我有加載內容使用AJAX。需要調用ajax加載的內容。我也嘗試了一些代碼,但沒有運氣與此。單擊AJAX加載的內容和動態ID事件
jQuery(document).ready(function(){
var itemId = '<?php echo $_item->getId(); ?>';
jQuery("#cart-sidebar").on("click", '.increment_qty_'+itemId, function(event) {
console.log("work");
});
jQuery("#cart-sidebar").on("click", '.increment_qty_<?php echo $_item->getId(); ?>', function(event) {
console.log("work");
});
});
你有什麼問題?你在哪裏叫阿賈克斯? – user7417866
當頁面第一次加載時,你會得到'itemId',它不是來自AJAX。 AJAX是否真的用'itemId'返回元素,還是動態改變? – Barmar
是的,我每次都得到itemId,但這個點擊事件js也加載到ajax成功 –