2009-10-20 49 views
1

选择网格元素这是一个后续问题ASP.NET How to pass container value as javascript argument无法通过jQuery的

达林季米特洛夫慷慨地使用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文档,但没有成功。



我失去了一些东西在这里?

+0

+1学习新事物! – Nescio 2009-10-20 02:28:50

+0

@thanks,Nescio:试图解决一个问题导致我变成了jQuery。 ;)学习这种方式很有趣。 – Sung 2009-10-20 02:29:56

回答

0

我不知道为什么选择通过#_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); 
      }); 
     }); 
    }); 
0

我所做的,以节省我在.aspx页面中使用的控制的完整ID:

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

然后,您可以只得到了id的值,然后使用在查询中知道使用哪一行。

0

乍一看,我想你只想要一个'$'而不是'^',你应该在你的选择器中定位ID而不是NAME。

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