<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function a(){
var str = new Date();
alert(str.getHours());
}
</script>
<title>无标题文档</title>
</head><body>
人名类<label></label>
<hr />
<form id="form2" name="form2" method="post" action="">
<label>
<input id ="b" type="checkbox" name="checkbox2" value="checkbox"/>
b</label>
<label>
<input id="a" type="checkbox" name="checkbox" value="checkbox"/>
a</label>
<input type="submit" value="s" onclick="a()"/>
</form></body>
</html>
为什么触发不了a函数?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function a(){
var str = new Date();
alert(str.getHours());
}
</script>
<title>无标题文档</title>
</head><body>
人名类<label></label>
<hr />
<form id="form2" name="form2" method="post" action="">
<label>
<input id ="b" type="checkbox" name="checkbox2" value="checkbox"/>
b</label>
<label>
<input id="a" type="checkbox" name="checkbox" value="checkbox"/>
a</label>
<input type="submit" value="s" onclick="a()"/>
</form></body>
</html>
为什么触发不了a函数?
a();
}
<script type="text/javascript">
function ab(){
var str = new Date();
alert(str.getHours());
}
</script>
<input id="a" type="checkbox" name="checkbox" value="checkbox"/>
a</label>
<input type="button" value="s" onclick="ab()"/>
id="a"和原来的函数a重名了;submit最好改成button;用js提交。
3楼正解,id="a"和函数a()重名了