javascript和ASP.NET控件前缀中的"this"

Bob*_*ith 0 javascript asp.net

我有代码,呈现以下HTML

<tr>
  <td>Control 1 with onclick="javascript:Test(this);" </td>
  <td>Control 2</td>
  <td><span><div>Control 3</div></span></td>
</tr>

function Test(myThis)
{
  //Here I would like to get references to the siblings of Control 1 (in this ex: Control 2, Control 3)
  //and disable them. Any ideas?

}
Run Code Online (Sandbox Code Playgroud)

我正在使用这种寻找兄弟姐妹的方法,因为这是在深度= 3的嵌套用户控件中,而ASP.NET指的是带有前缀的控件非常难,特别是如果我在页面上有多个控件实例.

Ben*_*man 5

如果您使用的是jQuery等javascript库,那么它变得非常简单:

$(this).siblings().disable();
Run Code Online (Sandbox Code Playgroud)

http://docs.jquery.com/Traversing/siblings#expr

如果您没有jQuery或类似的库,那么您必须手动执行:

function disableSiblingsOf(elem)
{
  var nodes = elem.parent.childNodes;
  for(var i=0; i<nodes.length; i++);
     if(nodes[i] != elem)
        nodes[i].disabled = true;
}
Run Code Online (Sandbox Code Playgroud)

这应该够了吧.