当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript判断单选框或复选框是否选中方法集锦

Javascript
纯JS半透明Tip效果代码
JavaScript 读URL参数增强改进版版
JS对URL字符串进行编码/解码分析
javescript完整操作Table的增加行,删除行的列子大全
js可填可选的下拉框
prototype Element学习笔记(篇一)
prototype Element学习笔记(篇二)
prototype Element学习笔记(Element篇三)
Prototype使用指南之selector.js说明
不唐突的JavaScript的七条准则整理收集
js判断变量是否空值的代码
Firefox getBoxObjectFor getBoundingClientRect联系
Div自动滚动到末尾的代码
javascript笔试题目附答案
javascript引导程序
js身份证验证超强脚本
JS给元素注册事件的代码
JavaScript函数、方法、对象代码
JS写的数字拼图小游戏代码[学习参考]
关于B/S判断浏览器断开的问题讨论

Javascript 中的 javascript判断单选框或复选框是否选中方法集锦


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 355 ::
收藏到网摘: n/a

提示:getEmementsByName方法的作用是根据 NAME 标签属性的值获取对象的集合。
样例一<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>判断单选框或复选框是否选中</title>
</head>
<body>
<input name="radio1" type="radio" value="test">
<button onClick="alert('单选项'+(document.getElementsByName('radio1')[0].checked? '':'没有')+'选中')">测试</button><br>
<input name="radio1" type="radio" value="test">
<button onClick="alert('单选项'+(document.getElementsByName('radio1')[1].checked?'':'没有')+'选中')">测试</button><br>
<input name="checkbox1" type="checkbox" value="test">
<button onClick="alert('多选项'+(document.getElementsByName('checkbox1')[0]. checked?'':'没有')+'选中')">测试</button><br>
<input name="checkbox1" type="checkbox" value="test">
<button onClick="alert('多选项'+(document.getElementsByName('checkbox1')[1].checked?'':'没有')+'选中')">测试</button>
提示:getEmementsByName方法的作用是根据 NAME 标签属性的值获取对象的集合。
</body>
</html>
样例二:
<form name="myform" action="" method="" onsubmit="return check()">
<input type="radio" name="picno" value="1">
<input type="radio" name="picno" value="2">
<input type="radio" name="picno" value="3">
<input type="submit" value="Submit">
</form>
<script language="JavaScript">...
function check()...{
var flag=0
for(i=0;i<myform.picno.length;i++)
if(myform.picno[i].checked==true)...{
flag=1
break
}
if(!flag)...{
alert("请先选择更换图片的位置")
return false
}
}
</script>