0
我有以下代碼將一個事件偵聽器附加到表單提交。我想調用的函數是'回調'。 這裏是東西:我不明白我應該如何參數傳遞給函數純Javascript - 在表單中執行回調提交eventlistener
if(form.addEventListener){
form.addEventListener('submit', interrupt, false);
}else if(form.attachEvent){
form.attachEvent('onsubmit', interrupt);
}
function interrupt(event){
//deal with form submission here
}
//OR (???)
interrupt = function(event){
//deal with form submission here
}
我知道這個問題似乎是基本的,但我真不(它應該是「事件」的說法?)不明白它應該如何工作...
您不必調用事件偵聽器。瀏覽器爲你做,它以'event'作爲參數。 – Oriol
用第一個函數中斷(事件){'並閱讀[Function declaration hoisting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function) – Anonymous0day