js monitors form submission events to prevent repeated form submissions

Use the submit button click event when calling, and the button turns gray after listening to submit, you can write the monitoring event single function as follows
$('#btn').click(function() {
    var items = {
        inputemail : [{type:'null', errMsg:zhffTip.langs.errTpl.noText.stringFormat('email')}, {type:'email', errMsg: zhffTip.langs.errTpl.shippingAddress.stringFormat('email')}],
        inputname : [{type: 'null', errMsg:zhffTip.langs.errTpl.noText.stringFormat('name')}, {type:'zhoren', errMsg: zhffTip.langs.errTpl.invalidName}],
    };


    return $('#addressEditForm' ).formCheck(items, {
        errinfoFinder: function(obj) { 
            var tip = obj.next("span");
            return tip;
         },
    });
});


//Bind the listener event
function addEventHandler(target,type,func){  
    if(target.addEventListener){  
        //监听IE9,谷歌和火狐  
        target.addEventListener(type, func, false);  
    }else if(target.attachEvent){  
        target.attachEvent("on" + type, func);  
    }else{  
        target["on" + type] = func;  
    }   
}  
function eventDis(e,btn){  
     $("#btn").attr("disabled",true); //按钮id
     //e.preventDefault();  //阻止表单提交
}
window.onload = function(){  
    var bindEventBtn = document.getElementById("addressEditForm");  //form 表单id  
    addEventHandler(bindEventBtn,"submit",eventDis); 
};


$(function(){
    eventDis(e,$("#btn"));
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325381118&siteId=291194637