<!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>