我有以下代码:
function showAddrBox() {
var prompt = document.getElementById('addr_prompt');
prompt.style.display = 'block';
document.generic_form.address.style.display = 'block';
document.generic_form.onsubmit = validateAddrForm;
}
function hideAddrBox() {
var prompt = document.getElementById('addr_prompt');
prompt.style.display = 'none';
document.generic_form.address.style.display = 'none';
document.generic_form.onsubmit = null;
}
问题是有时我有附加的附加功能onSubmit
,我想保留这些功能。我希望能够在onSubmit
事件中添加和删除单个函数,而不仅仅是使用onsubmit =
. 换句话说,我需要一种方法来完成这样的事情:
document.form.onsubmit += function;
document.form.onsubmit -= function;
有任何想法吗?