关于checkbox的小问题,请帮忙看看,谢谢

Fred_Mark 2005-12-08 04:46:53
var inputBox=document.getElementsByTagName("input");
if (inputBox != null)
{
var oneInput;
for (var j = 0; j < inputBox.length; j++)
{
oneInput = inputBox[j];
if(oneInput.type=="checkbox")
{
if(oneInput.checked==true)
{
..........
}
}
}
}
获得所有的input,然后判断是否checkbox,如果是,在查找是否选中,在“if(oneInput.checked==true)”出错.

不知道哪里错了,请帮忙看看,谢谢!
...全文
155 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
alen021 2005-12-24
  • 打赏
  • 举报
回复
对复选眶得判断要分两种
一种只有一个复选框
一种有两个以上复选框时
这两种情况得处理是不一样得
Marffin 2005-12-24
  • 打赏
  • 举报
回复
有时候还是用firefox调一下吧,javascript console和DOM inspector都是好东西啊
xxuu503 2005-12-23
  • 打赏
  • 举报
回复
回复人: mingxuan3000(铭轩) ( ) 信誉:100 2005-12-23 10:24:14 得分: 0



if(oneInput.checked==true) 也可以,




是啊!不过多走一部!
Fibona 2005-12-23
  • 打赏
  • 举报
回复
if(oneInput.checked)
{
mingxuan3000 2005-12-23
  • 打赏
  • 举报
回复
if(oneInput.checked==true) 也可以,
mingxuan3000 2005-12-23
  • 打赏
  • 举报
回复
var inputBox=document.getElementsByTagName("input");
if (inputBox != null) {
var oneInput;
for (var j = 0; j < inputBox.length; j++) {
alert("cc");
oneInput = inputBox[j];
if(oneInput.type=="radio"){
alert("bb");
if(oneInput.checked)
{
alert("aa");
}
}
}
}
这个我试过 完全可以
yesjoy 2005-12-22
  • 打赏
  • 举报
回复
看这里:
<!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=GBK" />
<title>无标题文档</title>
<script type="text/javascript">
var xlh = function(){
var inputBox=document.getElementsByName("input");
if (inputBox != null){
var oneInput;
for (var j = 0; j <inputBox.length; j++)
{
oneInput = inputBox[j];
if(oneInput.type=="checkbox")
{
if(oneInput.checked)
{
alert("哈哈,你选中的是"+oneInput.value);
}
}
}
}
}
</script>
</head>

<body>
<input name="input" type="checkbox" id="c1" value="c1" />c1
<input name="input" type="text" id="c2" value="c2" />c2
<input name="input" type="text" id="c3" value="c3" />c3
<input name="input" type="checkbox" id="c4" value="c4" />c4
<input name="input" type="button" value="test" onclick="xlh()"/>
</body>
</html>
Fred_Mark 2005-12-08
  • 打赏
  • 举报
回复
结贴
Fred_Mark 2005-12-08
  • 打赏
  • 举报
回复
不行啊,说Object required,555
黑马 2005-12-08
  • 打赏
  • 举报
回复
试一下if(oneInput.checked)

不行的话,再把document.getElementsByTagName改成document.getElementsById试试
redtank2005 2005-12-08
  • 打赏
  • 举报
回复
if(oneInput.checked)

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧