点击li弹出内容,并且动态添加li之后有效
<button onclick="addFunction()">点我增加</button>
<ul></ul>
<script type="text/javascript">
var num = 1;
var u=document.querySelector("ul");
function addFunction(){
var l=document.createElement('li')
var t=document.createTextNode(num);
l.appendChild(t);
u.appendChild(l);
num++
};
u.addEventListener('click',function(e){
if(e.target && e.target.nodeName.toUpperCase() === 'LI') {
console.log(e.target.innerHTML)
}
})
</script>