JS 动态生成节点_li

<script type="text/javascript">

var ul = document.getElementById("ul");

li = document.createElement("li"); 

txt = document.createTextNode("txt");

li.className = 'className';

li.onclick = function() {alert('helo');}

li.appendChild(txt);
		
ul.appendChild(li);

</script>

 

结论:

   

    li.onclick = function(){alert('hello')}                             IE,FF 都支持

 

    li.attachEvent("onclick",function(){alert('hello');});     IE支持

 

    li.setAttribute("onclick","alert('hello')");                       FF支持

 

你可能感兴趣的:(JavaScript,IE)