防止重复提交:javascript 防止重复提交



    很多时候我们都需要防止重复提交,这方面文章也比较多,实现途径差别也很大.以下是我写种控制提交方式.有些时候即使服务器能够识别重复提交,也会造成问题.比如需要很长等待时间操作,在首次提交后,不断重复提交,页面可能会死掉.用脚本来控制话可以防止这种问题.当然也可以脚本和服务器都进行控制,这样就比较完美了. 
    闲话少说,将以下脚本放置于页面顶部. 

document.IsPosted = false;
function CancelDubSubmit

     ((typeof(event.Value)  \"und\" || event.Value true) && !document.IsPosted)
    { 
        document.IsPosted = true;
        event.Value = true;
    }
    
    {          
        event.Value = false;
    }
}
<form id=\"Form1\" onsubmit=\"CancelDubSubmit;\" method=\"post\" runat=\"server\">
function __doPostBack(eventTarget, eventArgument)
{
     (!document.IsPosted)
    {
        var theform;
         (window.navigator.appName.toLowerCase.indexOf(\"netscape\") >  - 1)
        {
            theform = document.forms[\"Form1\"];
        }
        
        {
            theform = document.Form1;
        }
        theform.__EVENTTARGET.value = eventTarget.split(\"$\").join(\":\");
        theform.__EVENTARGUMENT.value = eventArgument;

        document.IsPosted = true;
        theform.submit;
    }
} 请将以上代码放置于页面原__doPostBack 的后.  [Page]

Tags:  重复提交 如何防止重复提交 防止表单重复提交 防止重复提交

延伸阅读

最新评论

  1. shfdghfhfd

发表评论