防止表单多次提交
时间:2010-08-23 来源:春风拂柳我自醉
//jQuery
①
<script type="text/javascript">
$("input:submit").each(function() {
var srcclick = $(this).attr("onclick");
if(typeof(srcclick)=="function"){
$(this).click(function() {
if (srcclick()) {
setdisabled(this);
return true;
}
return false;
});}
});
function setdisabled(obj) {
setTimeout(function() { obj.disabled = true; }, 100);
}
</script>
②
function disableOtherSubmit()
{
$("input:submit").each(function(i) {
setTimeout(function() { $("input:submit").eq(i).attr("disabled","true"); }, 100); });
}
//ASP.NET
Button_All.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(Button_All, ""));
Button_CurrentCount.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(Button_CurrentCount, ""));
Button_Between.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(Button_Between, ""));