![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> window.onload = function(){ var aBtn = document.getElementsByTagName('input'); var aP = document.getElementsByTagName('p'); var arr=['kk','li','ll']; for(var i = 0;i<aBtn.length;i++){ aBtn[i].index= i; aBtn[i].onclick = function(){ this.value = arr[this.index]; aP[this.index].innerHTML = arr[this.index]; } } } </script> </head> <body> <input type="button" value="btn1"/> <input type="button" value="btn2"/> <input type="button" value="btn3"/> <p>5</p> <p>7</p> <p>9</p> </body> </html>