asp.net - JavaScript 和 ASP.NET 控件前缀中的 "this"

标签 asp.net javascript

我有呈现以下 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?

}

我正在使用这种查找同级的方法,因为这是在深度 = 3 的嵌套用户控件中,并且 ASP.NET 引用带有前缀的控件,这是非常困难的,特别是当我在页面上有多个控件实例时。

最佳答案

如果您使用 jQuery 之类的 javascript 库,事情就会变得非常简单:

$(this).siblings().disable();

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;
}

这应该可以解决问题。

关于asp.net - JavaScript 和 ASP.NET 控件前缀中的 "this",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/512588/

相关文章:

javascript - 如何识别node.js缓冲区中的负数

php - 在通过 jQuery 上传到数据库之前,如何使用进度条和图像预览上传图像?

javascript - 如何使用 croppie js 裁剪图像并在 asp.net mvc 中上传

asp.net - asp.net如何在tablecell中添加新表

asp.net - 使用 Open Flash 图表的条件线图

javascript - HighCharts:如何使用回流以允许在更改大小后自动调整大小

c# - 如何让客户机上的程序从 ASP.NET 页面运行?

c# - 在 Request.Cookies 中找不到 .ASPXAUTH Cookie

javascript - 在 JavaScript 中验证文本框

javascript - 如何在javascript中正确转换html?