循环 添加事件
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>每個p添加點擊事件</title> </head> <body><p>點擊變色</p><p>點擊變色</p><p>點擊變色</p><p>點擊變色</p><p>點擊變色</p></body> <script type="text/javascript">var items=document.getElementsByTagName("p");for(i=0;i<items.length;i++){items[i].onclick=function(){this.style.color='red'}} </script> </html>
?
轉(zhuǎn)載于:https://www.cnblogs.com/jinsuo/p/7210709.html
總結(jié)
- 上一篇: 开个店要多少钱啊?
- 下一篇: 2017暑期挖坑计划(持续更新中~)