我正在使用 video.js
和 video.js
库正在通过脚本标记加载我想跟踪列表项上的点击功能并更新播放器菜单。
$(".vjs-menu-item").on("click" ,function(){ alert('selector');});
但这个不工作
$(document).on("click",".vjs-menu-item", function() {alert('document'); });
因此 $(document)
方法仅适用于添加在同一页面上的这些项目,即
<p id="vjs-menu-item"> click me </p>
最佳答案
这里选择器是id
,但您引用的是class
改成这样
$(document).on("click","#vjs-menu-item", function() {alert('documnet'); });
或者在html
中使用class
代替id
HTML
<p class="vjs-menu-item">Click me</p>
JS
$(document).on("click",".vjs-menu-item", function() {
alert('document');
});
关于javascript - $(document).on ("click") 不起作用,但 $ ('selector' ).on ("click") 起作用,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41311040/