//我的界面上只有一个checkbox,我想实现当用户选中checkbox时,把checkbox的值改为T,否则改为F,并把checkbox的值通过表单进行提交,我怎么试也试不通。请大家帮帮忙<!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" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementsByName("checkbox");
if (s.checked){
document.getElementByName("checkbox").value="T";
}else
{
document.getElementByName("checkbox").value="F";
};
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" name="checkbox" value="checkbox" />
test
</label>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementsByName("checkbox");
if (s.checked){
document.getElementByName("checkbox").value="T";
}else
{
document.getElementByName("checkbox").value="F";
};
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" name="checkbox" value="checkbox" />
test
</label>
</form>
</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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementsByName("checkbox")[0];
if (s.checked){
s.value="T";
}else
{
s.value="F";
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" name="checkbox" value="checkbox" />
test
</label>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementsByName("checkbox");
for(var i=0;i<s.length;i++)
{
if(s[i].checked)
{
s[i].value="T"
alert(s[i].value);
}
else
{
s[i].value="F"
}
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" name="checkbox" value="checkbox" />
test
</label>
</form>
</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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementById("ckb");
if (s.checked){
s.value="T";
}else
{
s.value="F";
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" id='ckb' name="checkbox" value="checkbox" />
test
</label>
</form>
</body>
</html>
LZ的问题是getElementsByName方法返回的是一个数值
当我不选中checkbox时,提交表单,就获取不到checkbox的值了。HTML端我用的Sandy945的代码,这是我写的一个asp脚本获取值。<%
response.write(Request("checkbox"))
%>
我想解决的问题是:
客户端选中/取消checkbox后,将checkbox的值修改为T/F,并且可以在asp脚本中显示checkbox的值
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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementById("ckb");
if (s.checked){
s.value="T";
}else
{
s.value="F";
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="test.asp">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" id='ckb' name="checkbox" value="checkbox" />
test
</label>
</form>
</body>
</html>ASP<%
response.write(Request("checkbox"))
%>
<!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" />
<title>无标题文档</title>
<script type="text/javascript">
function check(){
var s = document.getElementById("ckb");
var hid= document.getElementById("hid");
if (s.checked){
hid.value="T";
}else
{
hid.value="F";
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="Untitled-1.html">
<label>
<input type="submit" name="Submit" value="提交" onclick="check();" />
</label>
<label>
<input type="checkbox" id='ckb' name="checkbox" value="checkbox" />
test
</label>
<input type='hidden' id='hid' name='hidName' />
</form>
</body>
</html>
<%
response.write(Request("hidName"))
%>