在一种情况下,我必须将jQuery转换为等效的Javascript。
abc.js:
var sample = $('.class1');
sample.find('.class2').each(function(k, v) {
$(this).on('click', function() {
// some code
// return false ensures that other click event on same class2 in common.js is not called
return false;
})
})
common.js:
$(document).on('click', '.class2', function(e) {
// some code
});
在这里,我的任务是将abc.js转换为javascript等效文件。我在做什么:
const linkAreaList = document.querySelectorAll('class1');
linkAreaList.forEach((a, k) => {
a.addEventListener('click', (e) => {
e.preventDefault();
// here still click event ie $(document).on('click', '.class2', function (e) {}) is getting called . How to prevent the same
return false
})
})
仍在执行class2'common.js'的click事件。不执行class2的点击该如何进行?