<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function bodyonload() {
var inputs =
document.getElementsByTagName("input");
for (var i = 0; i <
inputs.length; i++) {
var inputS = inputs[i];
inputS.onclick =
btnclick;//这一步是给input动态添加onclick时间,这里btnclick后面没有括号,如果有括号就调用函数的意思了。
}
};
function btnclick() {//事件中是改变被点击按钮的value
var inputs =
document.getElementsByTagName("input");
for (var i = 0; i <
inputs.length; i++) {
var inputS = inputs[i];
if (inputS == window.event.srcElement) {//指向触发事件的node元素
inputS.value =
"呜呜";
}
else {
inputS.value =
"呵呵";
}
}
}
</script>
</head>
<body onload="bodyonload()">
<input type="button" value="呵呵" />
<input type="button"
value="呵呵" />
<input type="button" value="呵呵" />
<input type="button" value="呵呵" />
<input type="button"
value="呵呵" />
</body>
</html>