您的位置:首页 > Web前端 > JavaScript

javascript控制页面表单重复提交

2010-04-30 14:04 375 查看
// PageLoad事件
var onloadMethod = window.onload;
window.onload = window_Load;
function window_Load() {
var i;
var item;
// 全部连接的事件
for (i = 0; i < document.links.length; i ++) {
item = document.links[i]
Object.Aspect.around(item, "onclick", checkLoading);
}
// 全部按钮的事件
for (i = 0; i < document.forms[0].elements.length; i ++) {
item = document.forms[0].elements[i]
if (item.type == "button" ||
item.type == "submit" ||
item.type == "reset") {
Object.Aspect.around(item, "onclick", checkLoading);
}
}
if (onloadMethod != null && typeof (onloadMethod) == "function") {
// 执行Page的onload事件
return onloadMethod();
} else {
return true;
}
}
// 防止重复提交
var checkLoading = function(invocation) {
if (isDocumentLoading()) {
//alert("now loading…");
return false;
}
return invocation.proceed();
}
// 当前页面提交状态判断
function isDocumentLoading() {
return (document.readyState != null &&
document.readyState != "complete" &&
document.readyState != "interactive");
}
// Aspect 用
Object.Aspect = {
_around: function(target, methodName, aspect) {
var method = target[methodName];
target[methodName] = function() {
var invocation = {
"target" : this,
"method" : method,
"methodName" : methodName,
"arguments" : arguments,
"proceed" : function() {
if (!method) {
return true;
}
return method.apply(target, this.arguments);
}
};
return aspect.apply(null, [invocation]);
};
},
around: function(target, methodName, aspect) {
this._around(target, methodName, aspect);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: