form submit拦截 表单提交拦截

[code]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>previous form submit</title>
<script type="text/javascript">
posted = false;
function submitForm(form)
{
    form.submit();
}

/**
 * This is a form submit interceptor.
 * In order to avoid duplicate submitting error, it will check posted flag. if posted flag is still false, will set it to true.
 * Usage:
 *     <body οnlοad="formSubmitInterceptor();">
 * @author yangjincheng
 */
function formSubmitInterceptor()
{
    var forms = document.getElementsByTagName("form");
    if(!forms.length)
    {
        //if no form tag exists.
        return;
    }
    for(var i = 0; i < forms.length; i++)
    {
        form = forms[i];
        form.preFormSubmit = form.submit;
        form.submit = function(){
                if(typeof posted == "undefined")
                {
                    alert("You must define variable: posted !!!");
                    return;
                }
                if(posted)
                {
                    alert("form is submitted!");
                    return;
                }
                //1: When form submit, if posted is still false, set it to true.
                if(!posted)
                {
                    posted = true;
                }
                //2: Then submit form.
                alert("Previous submit, you can add your code here...");
                form.preFormSubmit();
            }
    }
}

</script>
</head>
<body οnlοad="formSubmitInterceptor();">
<form action="http://wwww.google.com" method="get" enctype="application/x-www-form-urlencoded">
<input name="name1" />
<input name="name2"/>
<input type="button" οnclick="submitForm(this.form);" value="提交">
</form>
</body>

</html>

[code]

转载于:https://my.oschina.net/fdhay/blog/17508

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值