我的应用程序有数百页。现在我必须disablePage
在onSubmit
表单上附加一个事件。我不想去每一页写:
<form name="frmname" onSubmit="disablePage();">
我现在正在做的是:-
摘自 common.js 文件;[包含在所有页面中]
/* we have to attach 'attachFormSubmit' method on onLoad event,
otherwise forms[0] will always be null. If there is any alternative,
then please suggest one */
if (window.addEventListener){
window.addEventListener('load', attachFormSubmit, false);
} else if (window.attachEvent){
window.attachEvent('onload', attachFormSubmit );
}
function attachFormSubmit(){
forms = document.getElementsByTagName('Form');
if ( forms[0] ){ // there is only one form in all pages
if (forms[0].addEventListener){
forms[0].addEventListener('submit', disablePage, false);
} else if (forms[0].attachEvent){
forms[0].attachEvent('onsubmit', disablePage);
}
}
}
function disablePage(){
document.getElementById("pageHideDivID").style.display='inline';
}
到此为止一切都很好,disablePage()
附在所有页面的表单上。
但问题是,如果有人已经附加了任何方法,onSubmit
那么onLoad
也应该执行该方法。我猜根据我的代码,代码永远不会被执行。我应该怎么做才能链接他们的方法呢?
请不要使用 JQuery。