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