<!DOCTYPEhtmlPUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
//页面有多个input控件,当点击其中一个的时候,就将这个控件的value属性设为嘿嘿。其他的设为哈哈
function addVal() {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i< inputs.length; i++) {
//获取表单,为表单添加onclick事件。而它的onclick事件就是调用click函数
inputs[i].onclick=click
}
}
//为当前点击的控件设置value属性
function click() {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i< inputs.length; i++) {
var input = inputs[i];
//window.event.srcElement是取得引发事件的控件(表单)
if (input == window.event.srcElement) {
input.value ="嘿嘿";
}
else {
input.value ="哈哈";
}
}
}
</script>
</head>
<bodyonload="addVal()">
<inputtype="button" value="哈哈"/>
<inputtype="button" value="哈哈"/>
<inputtype="button" value="哈哈"/>
<inputtype="button" value="哈哈"/>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
//页面有多个input控件,当点击其中一个的时候,就将这个控件的value属性设为嘿嘿。其他的设为哈哈
function addVal() {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
//获取表单,为表单添加onclick事件。而它的onclick事件就是调用click函数
inputs[i].onclick=click
}
}
function click() {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
//window.event.srcElement是取得引发事件的控件(表单)
if (input == window.event.srcElement) {
input.value = "嘿嘿";
}
else {
input.value = "哈哈";
}
}
}
</script>
</head>
<body onload="addVal()">
<input type="button" value="哈哈" />
<input type="button" value="哈哈" />
<input type="button" value="哈哈" />
<input type="button" value="哈哈" />
</body>
</html>