【问题标题】:two input submits, how to know which one was clicked using jQuery两个输入提交,如何知道使用jQuery点击了哪一个
【发布时间】:2016-02-05 08:03:01
【问题描述】:

我有一个带有两个输入的 html 站点,我使用 jQuery 为每个按钮添加了一些功能。我怎么知道点击了哪一个?

$(function(){ 
    $("#form1").submit(function(event){
        if("clicked subit 1"){ //How to do this
              alert("Submit1");
        } else {
              alert("Submit2"); 
        }
    });
});
<form name="form1" id="form1" method="post" action="#">
    <input type="submit" value="Submit1" /> 
    <input type="submit" value="Submit2"/>
</form>

【问题讨论】:

    标签: jquery html forms submit


    【解决方案1】:
    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    
    <script>
      $(document).ready(function () {
        $('input[type="submit"]').click(function (event) {
          if ($(this).val() == "Submit1") {
              alert("Submit1")
          }
          else {
              alert("Submit2")
          }
        });
      });
    </script>
    </head>
    <body>
        <form name="form1" id="form1" method="post" action="#">
              <input type="submit" value="Submit1" /> 
              <input type="submit" value="Submit2"/>
        </form>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      相关资源
      最近更新 更多