手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >js 判断checkbox是否选中的操作方法
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 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 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)+"个没有选择")

}

}

</script>

<input type=button 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 value="检测">

【js 判断checkbox是否选中的操作方法】相关文章:

js禁止页面刷新与后退的方法

JS/Jquery判断对象为空的方法

javascript实现点击商品列表checkbox实时统计金额的方法

jQuery切换所有复选框选中状态的方法

js控制网页前进和后退的方法

js实现文本框选中的方法

javascript用函数实现对象的方法

jquery判断至少有一个checkbox被选中的方法

jQuery实现不断闪烁文字的方法

js判断鼠标位置是否在某个div中的方法

精品推荐
分类导航