手机
当前位置:查字典教程网 >编程开发 >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+html5实现canvas绘制圆形图案的方法

js获取滚动距离的方法

js兼容火狐获取图片宽和高的方法

Node.js重新刷新session过期时间的方法

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

jQuery实现返回顶部效果的方法

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

javascript用函数实现对象的方法

jQuery判断指定id的对象是否存在的方法

判断Checkbox和Radio的一种方法

精品推荐
分类导航