2011-05-13 21 views
0

我通过以下jquery绑定点击到一系列asp:hyperlinkjQuery - 获取hyperlink.navigateurl的值

$(".dummyIdentifier").click(function() { 
      $("#divLineItemComments").dialog("open"); 
      return false; 
     }); 

这很好用。现在,我需要传递Hyperlink.NavigateUrl OnClick的值。所以我可以用ajax包含值$.get()

如何获取点击的超链接的值?我不知道它是ID,因为超链接是由ASP.NET动态生成的。

  <asp:TemplateField HeaderText="Notes" ItemStyle-CssClass="NoMargin NoPadding" SortExpression="lineNotes"> 
      <ItemTemplate> 
       <asp:HyperLink id="notesHl" runat="server" text='<%# Bind("lineNotes") %>' Font-Underline="true" Font-Bold="true" CssClass="dummyPhysicalNoteIdentifier"></asp:HyperLink> 
      </ItemTemplate> 
      <ItemStyle Font-Size="Smaller" Height="10px" Width="10px" Wrap="True" /> 
     </asp:TemplateField> 

回答

4

你可以这样说:

$(".dummyIdentifier").click(function() { 
    $("#divLineItemComments").dialog("open"); 

    var url = $(this).attr('href'); 

    return false; 
}); 
+1

+1漂亮多了。你也可以直接调用'this.href'并避免在jQuery中重新包装你的对象。 – Tejs 2011-05-13 16:30:10

+0

哈哈yeh - jQuery在我的js心态中如此根深蒂固,现在我倾向于总是使用它,有时候这对我来说是不利的,因为在这种情况下! – jcvandan 2011-05-16 08:42:27