为什么加了<span></span>就不起作用了
效果:取得选中的值.
<table style="width: 205px; height: 64px" id="myTable" border="1" >
<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++){
if(inputs[i].type=="checkbox"&&inputs[i].checked){
selectedText +=inputs[i].nextSibling.value + ","+inputs[i].parentElement.nextSibling.innerText;
}
}
check_ids.value =selectedText;
}
</script>
如在checkbox之间加了<span>...</span>
(如<span style"...""><input id="Checkbox2" type="checkbox"></span>就取不到.
------解决方案--------------------inputs[i].parentElement.parentElement.nextSibling.innerText;