我正在调试一些 jQuery 代码,发现单击时该代码部分不会触发。
我的 HTML/PHP 是:
$cartlink .= "<a class='add_to_cart button' data-id='{$product->id}' href='javascript:;' {$style}>{$label}</a>";
jQuery:
<script>
jQuery(window).on('click', 'a.add_to_cart.button', function() {
console.log("batman");
});
</script>
最佳答案
您需要将window
替换为document
。因为 window
对象不包含 DOM 节点。不过,您也可以使用 jQuery(window.document)
来查找 DOM 节点。
The window object represents a window containing a DOM document; the document property points to the DOM document loaded in that window
关于javascript - jQuery 代码未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24460972/