2012-04-27 50 views
2

我想在一個的onclick執行兩個功能,多種功能的onClick

我下面的代碼:

<Script> 

function checkSubmit(){ 

if(confirm('Are you sure you want to submit the data?');) 
    sendData(); 
} 

</Script> 

按鈕:

<input type="submit" id="send_data" class="send_data" value="Send" onclick="checkSubmit()"/> 

它不執行送出數據( )函數,任何想法如何在一個onclick下執行這兩個函數?

+0

爲什麼你確認功能之後分號嗎? – EnKrypt 2012-04-27 12:08:43

回答

2

格式的代碼通常更好這應該做工精細

if(confirm('Are you sure you want to submit the data?')) { // no ; and open the bracket 
    sendData(); 
} 
1

試試這個代碼:

function checkSubmit() { 
    if (confirm('Are you sure you want to submit the data?')) 
     sendData(); 
} 

function sendData() { alert("data sent"); }