h5 jQuery 动态添加的元素添加 绑定事件
作者:程序员11 时间:2023-05-17 人气:259 QQ交流群\邮箱:1003265987@qq.com
h5 jQuery 动态添加的元素添加
绑定事件
要展示的内容
1.监听事件,先判断是否存在
if(document.body.contains(document.getElementById("logOut"))) { document.querySelector("#logOut").addEventListener("click", function () { that.msg("已退出", 1) localStorage.clear() setTimeout(() => { location.href = "/boss/login" }, 1200) }) }
2.window监听事件
window.addEventListener('load', function () { })
3.select监听事件
$(document).on("change","#sourceSelect", function() {//方法二,这是一个事件委托方法,是给页面开始加载欠就存在的元素加 selectedDeviceId = sourceSelect.value; const zxingLibrary = document.getElementById('zxingLibrary') zxingLibrary.style.zIndex = -1 });
4.delegate监听绑定事件
$("body").delegate("#startButton","click", function() {//方法二,这是一个事件委托方法,是给页面开始加载欠就存在的元素加 console.log('startButton',selectedDeviceId) let that = this const zxingLibrary = document.getElementById('zxingLibrary') zxingLibrary.style.zIndex = 1000 codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => { if (result) { console.log(result) codeReader.stopStreams() zxingLibrary.style.zIndex = -1 let index = that.dataset.index let name = that.attributes[1].nodeValue callback(result.text,index,name) // document.getElementById('result').textContent = result.text } if (err && !(err instanceof ZXing.NotFoundException)) { console.error(err) // document.getElementById('result').textContent = err } }) console.log(`Started continous decode from camera with id ${selectedDeviceId}`) });
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。
h5 jQuery 动态添加的元素添加 绑定事件---相关文章
HTML5-热门文章
活跃用户












