js获取checkbox中所有选中值及input后面所跟的文本
2009-01-20 10:58
656 查看
<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>
解释:
nextSibling是获得当前对象的下一个对象
nodeValue是返回一个节点的值
<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>
解释:
nextSibling是获得当前对象的下一个对象
nodeValue是返回一个节点的值
相关文章推荐
- js获取checkbox中所有选中值及input后面所跟的文本
- js获取checkbox中所有选中值及input后面所跟的文本 .
- js获得checkbox选中值及input后面的文本
- js如何获得多个checkbox选中的值及input后面所跟的文本
- 在JS中获得checkbox选中值及input后面的文本
- js获得checkbox选中值及input后面的文本
- jquery 获取所有checkbox选中input
- JS选中checkbox后获取table内一行TD所有数据的方法
- Js选中checkbox后获取table内一行TD所有数据
- JS和后台获取复选框(checkbox)选中项后的文本内容
- JS选中checkbox后获取table内一行TD所有数据的方法
- js 获取所有选中的checkbox单选框
- JS中获取页面单选框radio和复选框checkbox中当前选中的值
- js实现选中所有的checkbox
- js和jq获取下来列表选中项的值和文本
- jquery获取所有选中的checkbox
- Angularjs 获取checkbox所有选中的值
- js获取下拉列表选中项的值和文本(select)以及获取单选按钮(radio)组的值和修改选中项[转]
- JS 控制checkbox 获取 全选 全不选 一行不选择全选则不被选择 所有选择全选被选择
- JQuery EasyUi Tree获取所有checkbox选中节点的id和内容