废话不多说代码如下:
方法一:
<em>v</em>ar pArys=document.getElementsByClassName("ps");
for(var i = 1; i <= pArys.length; i++){
//alert(i)
var pAry = document.getElementById("p"+i);
pAry.onclick=function(){
this.style.fontSize="39px";
}
}
var pArys=document.getElementsByClassName("ps");
for(var i = 1; i <= pArys.length; i++){
//alert(i)
var pAry = document.getElementById("p"+i);
pAry.onclick=function(){
this.style.fontSize="39px";
}
}
html代码:
<body> <p id="p1" class="ps">事件1</p> <p id="p2" class="ps">事件2</p> <p id="p3" class="ps">事件3</p> <p id="p4" class="ps">事件4</p> </body>
原文地址:http://blog.csdn.net/li_li_lin/article/details/41283433