日期:2014-05-16  浏览次数:20357 次

如果把文本框放入第一列,怎么取得值?
//效果:取得选中行的值
<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" ><input type="text" value="5" > </td >  
<td >小明 </td >  
</tr >  
<tr >  
<td > <input id="Checkbox2" type="checkbox" > <input type="text" value="8" > </td >  
<td >小强 </td >  
</tr >  
<tr >  
<td > <input id="Checkbox3" type="checkbox" > <input type="text" value="10" > </td >  
<td >小华 </td >  
</tr > 
</table > 
   
<input type="text" id="check_ids" / > <button onclick="setCheck();" >点我 </button > 

<script type="text/javascript" > 
function setCheck(){ 
var selectedText = ""; 
var inputs = document.getElementById("myTable").getElementsByTagName("input"); 
for(i = 0;i < inputs.length;i++){ 
//var id = inputs[i].value + ","+inputs[i++].parentElement.nextSibling.nextSibling.innerText; 
if(inputs[i].checked == true){ 
selectedText += inputs[i+1].value + ","+inputs[i].parentElement.nextSibling.nextSibling.innerText; 


check_ids.value = selectedText; 
}  
</script >

------解决方案--------------------
就是之间的那个
<input id="Checkbox2" type="checkbox" > <input type="text" value="8" > 
要改成
<input id="Checkbox2" type="checkbox"><input type="text" value="8">