教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js 判断checkbox是否选中的方法

js 判断checkbox是否选中的方法

发布时间:2015-02-16   编辑:jiaochengji.com
本文介绍下,使用js脚本判断checkbox复选框是否选中的方法,通过一个例子来加以说明,有兴趣的朋友参考研究下吧。

本节主要内容:
利用js判断是否选中CheckBox的方法
 
核心提示: js判断是否选中CheckBox复选框中的值。

例子:
 

复制代码 代码示例:

//第几个没有选
<input type="checkbox" name="checkbox1" checked>
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1" checked>
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<script language=javascript>
function check(obj)
{

for(i=0;i<document.all(obj).length;i++)
{
if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择")
}
}
</script>
<input type=button onclick="check('checkbox1')" value="检测">

//一个也没有选
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<Script Language="JavaScript">
function check(obj){
for(i=0;i<document.all(obj).length;i++){
if(document.all(obj)(i).checked){
return;
}
}
window.alert('一个也没有选!');
}
</Script>
<input type=button onclick="check('test');" value="检测">

//第几个没有选
<input type="checkbox" name="checkbox1" checked>
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1" checked>
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<script language=javascript>
function check(obj)
{

for(i=0;i<document.all(obj).length;i++)
{
if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择")
} www.jiaochengji.com
}
</script>
<input type=button onclick="check('checkbox1')" value="检测">

//一个也没有选
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<input type="checkbox" name="test">
<Script Language="JavaScript">
function check(obj){
for(i=0;i<document.all(obj).length;i++){
if(document.all(obj)(i).checked){
return;
}
}
window.alert('一个也没有选!');
}
</Script>
<input type=button onclick="check('test');" value="检测">

您可能感兴趣的文章:
js判断复选框checkbox是否选中并取出值
jquery checkbox复选框是否选中的检测代码
jquery 判断checkbox(复选框)是否被选中
JS验证radio和checkbox是否选中
JS动态判断radio是否选中的方法
jQuery判断checkbox是否被选中的三种方法
jquery判断checkbox是否选中的代码参考
radio实现checkbox效果 再次点击取消选择
js 检验(input、radio、checkbox、textarea)必填项的代码
js 判断checkbox是否选中的方法

关键词: checkbox  选中   
[关闭]
~ ~