0

我有gridview,里面有一个按钮,我想在点击时调用一个jQuery函数。

这是我的提示:

<asp:GridView ID="gvContactUs" runat="server" AllowSorting="True" AutoGenerateColumns="False"
     DataKeyNames="ContactID" Width="100%" CellPadding="3" CellSpacing="1" 
     OnPageIndexChanging="gvContactUs_PageIndexChanging"
     OnRowCommand="gvContactUs_RowCommand" 
     OnRowDataBound="gvContactUs_RowDataBound"
     OnRowDeleting="gvContactUs_RowDeleting" 
     OnSorting="gvContactUs_Sorting" AllowPaging="True"
     BackColor="White" BorderColor="White" BorderStyle="Ridge" 
     BorderWidth="2px" GridLines="None">
     <Columns>
         <asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="3%">
             <ItemTemplate>
                 <asp:Button Text="text" ID="hello" runat="server" />
             </ItemTemplate>
             <HeaderStyle Width="7%" />
             <ItemStyle HorizontalAlign="Center" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Name" ItemStyle-HorizontalAlign="Left">
             <ItemTemplate>
                 <%#Eval("Name")%>
             </ItemTemplate>
             <ItemStyle HorizontalAlign="Left" />
             <HeaderStyle Width="11%" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Email" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="13%">
             <ItemTemplate>
                 <a href="mailto:<%#Eval("Email")%>" class="EmailLink">
                 <%#Eval("Email")%></a>
             </ItemTemplate>
             <HeaderStyle Width="13%" />
             <ItemStyle HorizontalAlign="Center" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Phone" HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="7%">
             <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
             <ItemStyle HorizontalAlign="Center" Width="40px" />
             <ItemTemplate>
                 <%#Eval("Phone")%>
             </ItemTemplate>
             <HeaderStyle Width="8%" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Status" HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="7%">
             <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
             <ItemStyle HorizontalAlign="Center" Width="40px" />
             <ItemTemplate>
                  <%#Eval("Subject")%>
             </ItemTemplate>
             <HeaderStyle Width="13%" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="7%">
             <ItemTemplate>
                 <asp:LinkButton CommandName="Delete" CommandArgument='<%#Eval("ContactID") %>' runat="server" ID="lnkbtnDelete">
                     <img src="Images/delete.gif" border="0" alt='Click to Delete this Entry' title='Click to Delete this Entry' />
                 </asp:LinkButton>
             </ItemTemplate>
             <HeaderStyle Width="7%" />
             <ItemStyle HorizontalAlign="Center" />
         </asp:TemplateField>
     </Columns>
     <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
     <HeaderStyle Height="30px" BackColor="#3E3050" Font-Bold="True" ForeColor="#ffffff" />
     <PagerStyle ForeColor="Black" BackColor="#C6C3C6" HorizontalAlign="Right" />
     <RowStyle Height="25px" BackColor="#DEDFDE" ForeColor="Black" />
     <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
     <SortedAscendingCellStyle BackColor="#F1F1F1" />
     <SortedAscendingHeaderStyle BackColor="#594B9C" />
     <SortedDescendingCellStyle BackColor="#CAC9C9" />
     <SortedDescendingHeaderStyle BackColor="#33276A" />
 </asp:GridView>

jQuery代码是:

 $('[id$=hello]').live('click', function (e) {
        alert('hi8');

    });


    $(function () {

        $('input[id$=hello]').click(function () {

            alert('hikkk');
            return false;
        });
    });

这两件事我已经尝试过,但仍然无法调用 jQuery 函数。请帮我...

4

4 回答 4

2

使用属性包含选择器*而不是属性以 . 结尾 $。还要确保您已成功包含所需的 jQuery 库。

$(function () {    
      $('input[id*=hello]').click(function () {    
            alert('hikkk');
            return false;
      });
});
于 2013-02-07T09:36:14.633 回答
0

试试这个

$(document).ready(function() {
    $('input[id$=hello]').click(function() {
        //Your logic goes here
        alert('Im clicked');
    });
});
于 2013-02-07T09:37:26.123 回答
0

你为什么不在你OnClientClick的按钮上使用

  <asp:Button Text="text" ID="hello" runat="server" OnClientClick="return check();" />

<script type="text/javascript">
      function check()
      {
              alert("hi")
              return false;
      }
</script>
于 2013-02-07T09:46:33.070 回答
0

试试这个:

$(document).on('click', '[id*="hello"]', function(){
   alert('clicked.');
});
于 2013-02-07T09:47:05.690 回答