// 循环创建10个li标签,当点击li标签时,打印其对应的索引
<ul id="list"></ul>
function loadNode(len) {
var html = '';
for (let index = 0; index < 10; index++) {
html += '<li>'+index+'</li>';
}
var list = document.getElementById('list');
list.onclick = function(event) {
event = event || window.event;
var target = event.target || event.srcElement;
if(target.nodeName.toLowerCase() === 'li') {
console.log(target.innerText);
}
}
list.innerHTML = html;
}
loadNode();