js獲取checkbox值的方法
更新時間:2015年01月28日 15:31:15 投稿:shichen2014
這篇文章主要介紹了js獲取checkbox值的方法,涉及js針對節(jié)點的操作技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了js獲取checkbox值的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復制代碼 代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js</title>
</head>
<script language="javascript">
function aa(){
var r=document.getElementsByName("r");
for(var i=0;i<r.length;i++){
if(r[i].checked){
alert(r[i].value+","+r[i].nextSibling.nodeValue);
}
}
}
</script>
<body>
<form name="form1" method="post" action="">
<input type="checkbox" name="r" value="1">a<br>
<input type="checkbox" name="r" value="2">b<br>
<input type="checkbox" name="r" value="3">c<br>
<input type="checkbox" name="r" value="4">d<br>
<input type="checkbox" name="r" value="5">e<br>
<input type="checkbox" name="r" value="6">f<br>
<input type="checkbox" name="r" value="7">g<br>
<input type="checkbox" name="r" value="8">h<br>
<input type="checkbox" name="r" value="9">i<br>
<input type="checkbox" name="r" value="10">j<br>
<br>
<input type="button" onclick="aa()" value="button">
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js</title>
</head>
<script language="javascript">
function aa(){
var r=document.getElementsByName("r");
for(var i=0;i<r.length;i++){
if(r[i].checked){
alert(r[i].value+","+r[i].nextSibling.nodeValue);
}
}
}
</script>
<body>
<form name="form1" method="post" action="">
<input type="checkbox" name="r" value="1">a<br>
<input type="checkbox" name="r" value="2">b<br>
<input type="checkbox" name="r" value="3">c<br>
<input type="checkbox" name="r" value="4">d<br>
<input type="checkbox" name="r" value="5">e<br>
<input type="checkbox" name="r" value="6">f<br>
<input type="checkbox" name="r" value="7">g<br>
<input type="checkbox" name="r" value="8">h<br>
<input type="checkbox" name="r" value="9">i<br>
<input type="checkbox" name="r" value="10">j<br>
<br>
<input type="button" onclick="aa()" value="button">
</form>
</body>
</html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
IE下通過a實現(xiàn)location.href 獲取referer的值
IE下采用window.location.href方式跳轉(zhuǎn)的話,referer值為空在標簽a里面的跳轉(zhuǎn)的話referer就不會空,下面是具體的實現(xiàn)代碼2014-09-09JS中如何實現(xiàn)Laravel的route函數(shù)詳解
這篇文章主要給大家介紹了JS中是如何實現(xiàn)Laravel的route函數(shù),文中通過示例代碼介紹的很詳細,相信對大家具有一定的參考價值,有需要的朋友們下面來一起看看吧。2017-02-02JavaScript讀二進制文件并用ajax傳輸二進制流的方法
這篇文章主要介紹了JavaScript讀二進制文件并用ajax傳輸二進制流的方法的相關(guān)資料,需要的朋友可以參考下2016-07-07uniapp微信小程序訂閱消息發(fā)送服務(wù)通知超詳細教程
在使用或開發(fā)小程序過程中,我們會發(fā)現(xiàn)消息通知是非常重要的一個環(huán)節(jié),下面這篇文章主要給大家介紹了關(guān)于uniapp微信小程序訂閱消息發(fā)送服務(wù)通知的相關(guān)資料,需要的朋友可以參考下2023-06-06js 如何實現(xiàn)對數(shù)據(jù)庫的增刪改查
JavaScript操作數(shù)據(jù)庫JS操作Access數(shù)據(jù)庫,跟其他語言操作差不多,總結(jié)了一下習慣代碼,需要的朋友可以參考下2012-11-11