簡體   English   中英

jQuery-如何實現取消按鈕

[英]JQuery - How to implement Cancel Button

<html>
  <body>
    <form class="totalpayment">
      <input class="paid" type="text" name="numberOne" />
      <input class="due" type="text" name="numberTwo" />
      <button>Add</button>
    </form>
    <p class="total"></p>  

    <script src="jquery.min.js"></script>
    <script>
      // Sum the value when submitting the form
      $(".totalpayment").submit(function(e){
        e.preventDefault();
        var paid = parseInt($('.paid').val());
        var due = parseInt($('.due').val());
        $(".total").html(paid + due);
      });
    </script> 
  </body>
</html>

我有一個將兩個數字加在一起的表格。 我的問題是,它只有一個按鈕,即添加按鈕。 假設我想為取消按鈕添加處理程序,以清除兩個框,我將如何實現呢?

只需再添加一個按鈕即可重置表單。 閱讀有關重置按鈕的更多信息

無需添加任何用於重置表單的處理程序。

<button type="reset" value="Cancel">Cancel</button>

樣例代碼:

 <html> <body> <form class="totalpayment"> <input class="paid" type="text" name="numberOne" /> <input class="due" type="text" name="numberTwo" /> <button>Add</button> <button type="reset" value="Cancel">Cancel</button> </form> <p class="total"></p> <script src="jquery.min.js"></script> <script> // Sum the value when submitting the form $(".totalpayment").submit(function(e){ e.preventDefault(); var paid = parseInt($('.paid').val()); var due = parseInt($('.due').val()); $(".total").html(paid + due); }); </script> </body> </html> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM