不太明白你想实现什么功能,其实只要form2.a就已经取到form2.s1对象了,像下面这样:
<!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> new document </title>
<script type="text/javascript">
function sto(a,b){
var x;
x = document.form2.a;
alert(a.value);
}
</script>
</head> <body>
<form name="form2">
Checkbox1<input type="checkbox" name="s1" id="s1" value="Value of s1" onclick="return sto(s1,4);" />
</form>
</body>
</html>或者用getElementById()的方法,像下面这样:
<!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> new document </title>
<script type="text/javascript">
function sto(a,b){
var x;
x = document.getElementById(a);
alert(x.value);
}
</script>
</head> <body>
Checkbox1<input type="checkbox" id="s1" value="Value of s1" onclick="return sto(s1,4);" />
</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> new document </title>
<script type="text/javascript">
function sto(a,b){
var x;
x = document.form2.a;
alert(a.value);
}
</script>
</head> <body>
<form name="form2">
Checkbox1<input type="checkbox" name="s1" id="s1" value="Value of s1" onclick="return sto(s1,4);" />
</form>
</body>
</html>或者用getElementById()的方法,像下面这样:
<!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> new document </title>
<script type="text/javascript">
function sto(a,b){
var x;
x = document.getElementById(a);
alert(x.value);
}
</script>
</head> <body>
Checkbox1<input type="checkbox" id="s1" value="Value of s1" onclick="return sto(s1,4);" />
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货