1. 程式人生 > >js給網頁中所有p元素新增onclick事件

js給網頁中所有p元素新增onclick事件

<script type="text/javascript">
    var p=document.getElementsByTagName("p");
    alert(p.length);
     for(var i=0;i<p.length;i++)
     {
     p[i].onclick=function(){
     alert("")
     }
     }
</script>