0
我想做一個窗體,其中有兩個提交按鈕。這是表格。如何使用帶多個提交按鈕的JQuery提交表單?
<form method="POST" id="addCreditsForm">
<div class="row">
<div class="col s12 m10 offset-m1 l10 offset-l1 input-field">
<input type="number" name="amount" id="amount" required/>
<label for="amount">Amount</label>
</div>
<div class="col s12">
<p id="addWithPaypal" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Paypal</p>
<p id="addWithInstamojo" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Instamojo</p>
</div>
</div>
</form>
我試圖用JQuery的做到這一點。這裏是JQuery代碼。
$(document).ready(function(){
$("#addWithPaypal").click(function(){
$("#addCreditsForm").attr('action'."paypal/add/credits");
$("#addCreditsForm").submit();
});
$("#addWithInstamojo").click(function(){
$("#addCreditsForm").attr('action'."instamojo/add/credits");
$("#addCreditsForm").submit();
});
});
但是當我點擊任何負責在事件上調用JQuery函數的元素時,JQuery不起作用。我嘗試在兩個按鈕的單擊事件上都觸發警報,但它不工作!
我不知道什麼是錯的。請幫助我!
是保持
.
,這就是解決方案!我怎麼會這麼笨,哈哈! –你可以接受答案,如果它幫助你@AdarshSojitra –