2014-02-16 84 views
-2

我想提交表單,但提交之前,我想調用按鈕 調用一個JS函數:我可以在html中使用按鈕提交嗎?

<input name="" type="submit" value="SEND"> // <----- submit this later 


<button type="button" id="button" onClick="validateForm()">SEND THIS BEFORE</button> // <<-- call this before submitting the form 

有沒有辦法在那裏結合在一起?

感謝

+1

只需使用功能.submit()形式 –

+0

的文檔是你的朋友http://api.jquery.com/submit –

回答

2

試試這個,它環繞一個form標籤,並添加一個onsubmit屬性。

<form onsubmit="validateForm()"> 
     <input type="submit" value="SEND"/> 
</form> 
0

裏面你的onclick功能,你只需要使用.submit()裏面的功能,當您需要它來發送表單。

0

你可以做各種事情,如:

$("#form").on("submit", function(){ 
    // do stuff here 
}); 

或者

$("#button").on("click", function(){ 
    // do stuff here 
    $("#form").submit(); 
}); 
相關問題