欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js 判斷checkbox是否選中的操作方法

 更新時(shí)間:2012年11月09日 15:27:08   作者:  
大家在很多場(chǎng)合也許會(huì)遇到判斷頁(yè)面是否有元素選中,下面介紹的是利用js判斷是否選中CheckBox的方法
核心提示: 大家在很多場(chǎng)合也許會(huì)遇到判斷頁(yè)面是否有元素選中,下面介紹的是利用js判斷是否選中CheckBox的方法。
//第幾個(gè)沒(méi)有選
復(fù)制代碼 代碼如下:

<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)+"個(gè)沒(méi)有選擇")
}
}
</script>
<input type=button onclick="check('checkbox1')" value="檢測(cè)">

//一個(gè)也沒(méi)有選
復(fù)制代碼 代碼如下:

<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('一個(gè)也沒(méi)有選!');
}
</Script>
<input type=button onclick="check('test');" value="檢測(cè)">

//第幾個(gè)沒(méi)有選
復(fù)制代碼 代碼如下:

<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)+"個(gè)沒(méi)有選擇")
}
}
</script>
<input type=button onclick="check('checkbox1')" value="檢測(cè)">

//一個(gè)也沒(méi)有選
復(fù)制代碼 代碼如下:

<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('一個(gè)也沒(méi)有選!');
}
</Script>
<input type=button onclick="check('test');" value="檢測(cè)">

相關(guān)文章

最新評(píng)論