我加入一个按钮,动态地根据DIV存在,所以我有这样的:点击不会按钮添加工作动态
function addVideoButton(id) {
var div = document.createElement('div');
div.className = 'video';
div.dataset.videoid = id;
div.dataset.params = "modestbranding=1&am;showinfo=0&vq=720&color=white&theme=light&fs=1"
div.innerHTML = '<button class="play c-btn"><use xlink:href="#play"></use>WATCH VIDEO</button>';
var title = findTitle();
document.getElementById(title).appendChild(div);
}
另外,我有下面的一块,所以当这些类型的按钮是点击,一个参数是拍摄(视频ID),然后视频是在一个模式发挥
// show frame for the video modal
$(this).find('.play').on("click", function() {
showFrame(getIframe(videoId, params), "video");
});
不过,我注意到,如果我动态添加按钮如上,然后单击事件绑定将无法正常工作,如果我点击了,它不会启动模式,我错过了什么?
使用vanilla JS,只需在addVideoButton函数内添加事件监听器 –