【问题标题】:Cannot select grid element through jQuery无法通过 jQuery 选择网格元素
【发布时间】:2010-12-08 04:59:28
【问题描述】:

这是ASP.NET How to pass container value as javascript argument的后续问题

Darin Dimitrov 使用jQuery 提供了his answer,
但由于某种原因,我无法选择我想要的网格行。

这是用于选择行的jQuery。

$(function() {
    $('#_TrustGrid input[name^=trustDocIDTextBox]').each(function(index) {
        $(this).click(function() {
            alert('Hello world = ' + index);
            setGridInEditMode(index);
        });
    });
});

这是实际输出的 HTML 标记。

<input 
    id="_TrustGrid_ctl16_ctl05_ctl00_trustDocIDTextBox" 
    type="text" value="198327493" 
    name="_TrustGrid$ctl16$ctl05$ctl00$trustDocIDTextBox"/>

我今晚才开始使用 jQuery,并浏览了
jQuery Selectors 官方文档,但没有成功。



我在这里遗漏了什么吗?

【问题讨论】:

  • @thanks, Nescio:试图解决一个问题让我就这样进入了 jQuery。 ;) 以这种方式学习非常有趣。

标签: asp.net jquery jquery-selectors


【解决方案1】:

我做了什么来保存我在 .aspx 页面中使用的控件的完整 ID:

<input type="hidden" 
       id="SubcontractorDropDownID" 
       value="<%= SubcontractorDropDown.ClientID %>" />

然后,您可以获取 id 的值,然后在查询中使用它来知道要使用哪一行。

【讨论】:

    【解决方案2】:

    乍一看,我认为您只需要一个“$”而不是“^”,并且您应该在选择器中定位 ID 而不是 NAME?

    $(function() {
        $('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
            $(this).click(function() {
                alert('Hello world = ' + index);
                setGridInEditMode(index);
            });
        });
    });
    

    【讨论】:

      【解决方案3】:

      我不知道为什么通过#_TrustGrid 选择不起作用。 我可以通过指定:input 来解决这个问题,如下所示。

          $(function() {
              //$('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
              $(':input[id$=trustDocIDTextBox]').each(function(index) {
                  $(this).click(function() {
                      alert('Hello world = ' + index);
                      setGridInEditMode(index);
                  });
              });
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-11
        • 1970-01-01
        • 1970-01-01
        • 2017-04-05
        • 2014-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多