<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>
window.onload = function (){
var aBtn = document.getElementsByTagName('input');
var ap = document.getElementsByTagName('P');
//想建立匹配对应关系, 就用索引值
var arr=['默默','张申','杜鹏'];
for(var i=0; i<aBtn.length;i++){
//自定义属性index. 定义索引值获取 0,1,2
aBtn[i].index=i;
aBtn[i].onclick=function(){
//alert(this.index);
//alert(arr[this.index]);
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>A</p>
<p>B</p>
<p>C</p>
</body>
</html>