您现在的位置是:首页 > 电脑技术查询 > web开发

怎么分别得到选中行的值

编辑:chaxungu时间:2022-10-02 23:18:06分类:web开发

如何分别得到选中行的值?
表MYtable
第一列(checkbox) 第二列(textbox) 第三列(名字)
checkbox已选中 textbox的值:5 小明
checkbox未选中 textbox的值:8 小强
checkbox已选中 textbox的值:9 小华
......
如何编历分别得到字符串:"5,9"和"小明,小华"

------解决方案--------------------
var tds = mytable.getElementsByTagName("td");
for(var i=0;i<tds.length;i++){
if(i%3==0){//第一列

}else if(i%3==1){//第二列

}else{//第三列
}
}
------解决方案--------------------
<table style="width: 205px; height: 64px" >
<tr >
<td >
checkbox </td >
<td >
user_id </td >
<td >
user_name </td >
</tr >
<tr >
<td >
<input id="Checkbox1" type="checkbox" onclick="setCheck(this)" / > </td >
<td >
1 </td >
<td >
彫hua </td >
</tr >
<tr >
<td >
<input id="Checkbox2" type="checkbox" onclick="setCheck(this)" / > </td >
<td >
2 </td >
<td >
彫hong</td >
</tr >
<tr >
<td >
<input id="Checkbox3" type="checkbox" onclick="setCheck(this)"/ > </td >
<td >
5 </td >
<td >
彫敀 </td >
</tr >
</table >

<input type="text" id="check_ids" / >

<script type="text/javascript" >
function setCheck(obj)
{
var id = obj.parentElement.nextSibling.innerText+","+obj.parentElement.nextSibling.nextSibling.innerText;
if(obj.checked==true)
{
document.getElementById("check_ids").value = document.getElementById("check_ids").value+id;
}
else
{
document.getElementById("check_ids").value = document.getElementById("check_ids").value.replace(id, ' ');
}
}
</script >

测试通过
------解决方案--------------------
我那text控件不是已经显示那一行的值了么?
------解决方案--------------------
textbox?BU ZHI DAO SHI SHA DONGDONG……

<table style="width: 205px; height: 64px" id="myTable">
<tr>
<td>checkbox</td>
<td>user_id</td>
<td>user_name</td>
</tr>
<tr>
<td><input id="Checkbox1" type="checkbox"></td>
<td><input type="text" value="5"></td>
<td>小明</td>
</tr>
<tr>
<td><input id="Checkbox2" type="checkbox"></td>