首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

doc可否得到<td>行 里某个文字的值

2012-08-25 
doc能否得到td行 里某个文字的值c# asp.net在一个 aspx里程序动态生成以下脚本tdinput idDropDownC

doc能否得到<td>行 里某个文字的值
c# asp.net
在一个 aspx里 
程序动态生成以下脚本
<td><input id="DropDownCheckList2_0" type="checkbox" name="DropDownCheckList2:0" /><label for="DropDownCheckList2_0">Mystery</label></td>
</tr><tr>
<td><input id="DropDownCheckList2_1" type="checkbox" name="DropDownCheckList2:0" /><label for="DropDownCheckList2_0">Myste66ry</label></td>
</tr><tr>
(DropDownCheckList2_i是 动态生成的 ,数量是100个)

js 有没有办法用doc来解决这个问题(当 
var condition;
  for(i = 0; i < 100; i++)
  {
  var droptmp="DropDownCheckList2_"+i;
  if(document.getElementById(droptmp).checked)
  condition=i;------------------------------------如果 checkbox按下,<label for="DropDownCheckList2_0">Myste66ry</label> 要 把 “Myste66ry”-----------这个值给得到
  }  

DOC 似乎可以的(通过<input id="DropDownCheckList2_1"可以唯一确定<td>所在行
之后来得到Myste66ry的值
 ?

 

[解决办法]
可以

HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>无标题页</title>    <script type="text/javascript">       window.onload = function(){           var chColleciton = document.getElementById("tb").getElementsByTagName("input");           var label;           for(var i=0;i<chColleciton.length;i++){              if(chColleciton[i].type=="checkbox"&&chColleciton[i].checked){                  label = chColleciton[i].nextSibling;                  while(label.nodeType!=1){                    label = label.nextSibling;                  }                  alert(label.innerHTML)              }           }       }    </script></head><body>    <table id="tb">        <tr>            <td>                <input id="DropDownCheckList2_0" type="checkbox" name="DropDownCheckList2:0" /><label                    for="DropDownCheckList2_0">Mystery</label>            </td>        </tr>        <tr>            <td>                <input id="DropDownCheckList2_1" type="checkbox" checked="checked" name="DropDownCheckList2:0" /><label                    for="DropDownCheckList2_0">Myste66ry</label>            </td>        </tr>    </table></body></html> 

热点排行