冒泡:小的元素在大的元素里面,两个元素同时绑定事件。
点击小的会同时触发大的事件。 $('.big').on('click',function (e) {
console.log('big')
})
$(".small").on('click',function (e) {
console.log('small')
}
此时点击小的控制台会同时打印small big,
解决方法:$('.big').on('click',function (e) { console.log('big') e.stopPropagation()})$(".small").on('click',function (e) { console.log('small') e.stopPropagation()}
此时两个元素事件不再互相干扰