标签:cas console add class json nod ntb name listen
var ul = document.getElementById("ul") var json = [{"a":"1","b":"2","c":"3"},{"a":"2","b":"2","c":"3"},{"a":"3","b":"2","c":"3"}] // $.each(json,function (index,item) { // var li = ‘<li>‘+item.a+‘</li>‘ // $("ul").append(li) // }) for(i = 0;i<json.length;i++){ var lis = ‘<li>‘+json[i].a+‘</li>‘ $("ul").append(lis) } var addEvent = function(element,type,callback){ if(element.addEventListener){ element.addEventListener(type,callback,false); }else if(element.attachEvent){ element.attachEvent(‘on‘ + type,callback) } } addEvent(document.getElementById(‘ul‘), ‘click‘, function (event) { var event = event || window.event; var target = event.target || event.srcElement; if (target.nodeName.toLowerCase() == ‘li‘) { console.log(target.innerHTML) }
标签:cas console add class json nod ntb name listen
原文地址:https://www.cnblogs.com/guoxianglei/p/8979842.html