js 判斷checkbox是否選中的操作方法
更新時(shí)間:2012年11月09日 15:27:08 作者:
大家在很多場(chǎng)合也許會(huì)遇到判斷頁(yè)面是否有元素選中,下面介紹的是利用js判斷是否選中CheckBox的方法
核心提示: 大家在很多場(chǎng)合也許會(huì)遇到判斷頁(yè)面是否有元素選中,下面介紹的是利用js判斷是否選中CheckBox的方法。
//第幾個(gè)沒(méi)有選
<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)有選
<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)有選
<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)有選
<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è)">
//第幾個(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)文章
淺談JavaScript的對(duì)象類型之function
這篇文章主要介紹了淺談JavaScript的對(duì)象類型之function,函數(shù)(方法)是由事件驅(qū)動(dòng)的或者當(dāng)它被調(diào)用時(shí)執(zhí)行的可重復(fù)使用的代碼塊,需要的朋友可以參考下2023-05-05Javascript中eval函數(shù)的使用方法與示例
JavaScript有許多小竅門(mén)來(lái)使編程更加容易。其中之一就是eval()函數(shù),這個(gè)函數(shù)可以把一個(gè)字符串當(dāng)作一個(gè)JavaScript表達(dá)式一樣去執(zhí)行它。以下是它的說(shuō)明2007-04-04Javascript基礎(chǔ)教程之break和continue語(yǔ)句
文章通過(guò)示例向我們展示了javascript中的break和continue語(yǔ)句,兩個(gè)對(duì)比起來(lái),非常明了,需要的朋友可以參考下2015-01-01JavaScript 鏈?zhǔn)浇Y(jié)構(gòu)序列化詳解
這篇文章主要介紹了JavaScript 鏈?zhǔn)浇Y(jié)構(gòu)序列化詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09JavaScript高級(jí)程序設(shè)計(jì)(第3版)學(xué)習(xí)筆記11 內(nèi)建js對(duì)象
內(nèi)建對(duì)象是指由ECMAScript實(shí)現(xiàn)提供的、不依賴于宿主環(huán)境的對(duì)象,這些對(duì)象在程序運(yùn)行之前就已經(jīng)存在了2012-10-10JavaScript操作數(shù)組的常用方法總結(jié)
這篇文章總結(jié)了JavaScript操作數(shù)組的常用方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06深入document.write()與HTML4.01的非成對(duì)標(biāo)簽的詳解
本篇文章對(duì)document.write()與HTML4.01的非成對(duì)標(biāo)簽進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下2013-05-05