如何判断表格中行 checkbox 选中行里面 input 的值
有一个form 里面有一张表格 表格每一行前面有一个 checkbox 和多个 文本字段
form 递交的时候我只要拿到 checkbox 选中行 里面的 多个文本字段的值
这个js怎么写啊?
谢谢了
------解决方案--------------------参考
<script type= "text/javascript ">
function gett(){
var trs=document.getElementById( "tabt ").rows;
var aVal=new Array();
for(var i=0;i <trs.length;i++){
var ts=trs[i].getElementsByTagName( "input ");
if(ts[0].checked==true){
var texts=new Array();
for(var n=1;n <ts.length;n++){
texts.push(ts[n].value);
}
aVal.push(ts[0].name+ ":= "+texts.join( "||| "));
}
}
alert(aVal.join( "\n "));
}
</script>
<table id= "tabt ">
<tr> <td> <input type= "checkbox " name= "a "> <input type= "text "> <input type= "text "> <input type= "text "> </td> </tr>
<tr> <td> <input type= "checkbox " name= "b "> <input type= "text "> <input type= "text "> <input type= "text "> </td> </tr>
</table>
<input type= "button " onclick= "gett() " value= "得到值 ">
------解决方案-------------------- <script type= "text/javascript ">
function gett(){
var trs=document.forms[ "myf "].getElementsByTagName( "tr ");
var aVal=new Array();
for(var i=0;i <trs.length;i++){
var ts=trs[i].getElementsByTagName( "input ");
if(ts[0].checked==true){
var texts=new Array();
for(var n=1;n <ts.length;n++){
texts.push(ts[n].value);
}
aVal.push(ts[0].name+ ":= "+texts.join( "||| "));
}else{
trs[i].cells[0].innerHTML= " "; //删除未选中checkbox 相关input
}
}
alert(aVal.join( "\n "));
document.forms[ "myf "].submit();//提交表单
}
</script>
<form name= "myf ">
<table>
<tr> <td> <input type= "checkbox " name= "a "> <input type= "text "> <input type= "text "> <input type= "text "> </td> </tr>
<tr> <td> <input type= "checkbox " name= "b "> <input type= "text "> <input type= "text "> <input type= "text "> </td> </tr>
</table>
<input type= "button " onclick= "gett() " value= "得到值 ">
</form>