简体   繁体   English

确定在jQuery中单击了哪个asp.net提交按钮

[英]Identify which asp.net submit button has been clicked in jquery

I have two asp buttons in my form in asp. 我在ASP表单中有两个ASP按钮。 When I click on any of the submit buttons the function below is called which eventually calls callotherfunction(). 当我单击任何提交按钮时,将调用下面的函数,该函数最终将调用callotherfunction()。

  $("form").live("submit", function() { 
    callotherfunction();
});

I want to distinguish between the clicks and I want to run the callotherfunction(); 我想区分点击,我想运行callotherfunction(); only for 1 button. 仅用于1个按钮。

These are my two submit buttons: 这是我的两个提交按钮:

<asp:Button ID="btn1" runat="server" OnClick="Button1_Click" Text="Start Search" />      
<asp:Button ID="btn2" runat="server" OnClick="Button2_Click" Text="Export Data to Excel" />  

i have already tried identifying the button click bny using the code: 我已经尝试使用代码识别按钮单击bny:

$("input").click(function() { 
alert($(this).attr('id'));
});

I dont get any alert. 我没有收到任何警报。 How should I go about the process. 我应该如何处理。

$("#<%=btn1.ClientID %>").click(function() { ...});

像这样的东西

this code worked for me! 这段代码对我有用!

 $(document).ready(function () {
        $("input[id$='btn1']").click(function () {
            alert("button1");
        });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM