layout is ul > li > I and then dynamically added li uses event delegate method
now the problem is that every time the page is refreshed, the first click is executed to console.log ("1")
the dynamically generated elements of console.log ("1") console.log ("22222222222222")
are executed only on the second click. It is also the first time to click console.log ("1")
and the second time to click console.log ("1") console.log ("22222222222222)
how, it has always been console.log ("1") console.log ("22222222222222")
let aul = document.querySelector("-sharpcommentList")
aul.addEventListener("click",function(ev){
var target = ev.target;
while(target !== aul ){
if(target.tagName.toLowerCase() == "li"){
aa()
console.log("1")
break;
}
target = target.parentNode;
}
})
function aa(){
let zanli = document.getElementsByTagName("li")
for (var i = zanli.length - 1; i >= 0; i--) {
let num = i
zanli[i].addEventListener("click",function(ev){
console.log("222222222222")
zaning(num)
})
}
}
function zaning(num){
let zanli = document.getElementsByTagName("li")
for (let i = zanli.length - 1; i >= 0; i--) {
let findi = zanli[i].querySelector("i")
if (i==num) {
if(findi.className == "pt_praise active") {
return false;
}
findi.classList.add("active")
var numm = findi.innerHTML
findi.innerHTML = Number(numm)+1;
}
}
}