js获取checkbox中所有选中值及input后面所跟的文本 .
2012-05-15 21:25
591 查看
<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后面的文本
- Js选中checkbox后获取table内一行TD所有数据
- JS选中checkbox后获取table内一行TD所有数据的方法
- js 获取所有选中的checkbox单选框
- jquery 获取所有checkbox选中input
- JS和后台获取复选框(checkbox)选中项后的文本内容
- JS选中checkbox后获取table内一行TD所有数据的方法
- js获取checkbox复选框选中的选项实例
- jquery获取特定name所有选中的checkbox,支持IE9标准模式
- js实现选中所有的checkbox
- 在js中获取input check里选中的值
- js获取下拉列表选中项的值和文本(select)以及获取单选按钮(radio)组的值和修改选中项
- asp.net后台获取使用js方法input文本的value
- js获取在线编辑Word文档中选中的文本