复制代码 代码如下:
<asp:Button runat="server" Text="按我1" UseSubmitBehavior="false" OnClientClick="this.disabled=true;this.form.submit();"/>
复制代码 代码如下:
1: <script type="text/javascript">
function disableButton(button)
{
if (typeof (Page_ClientValidate) == 'function' && Page_ClientValidate() == false)
{
return false;
}
button.disabled = true;
return true;
}
</script>
<div>
<asp:TextBox runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxInput1"
ValidationGroup="Group1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:Button runat="server" Text="按我1" UseSubmitBehavior="false"
OnClientClick="disableButton(this);">
</asp:Button>
</div>
{
return false;
}
button.disabled = true;
}
function doubleClick()
{
var button1 = document.getElementById('btnPostBack1');
button1.onclick();
button1.onclick(); //模拟重复点击2次
}
</script>
<div>
<asp:TextBox runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxInput1"
ValidationGroup="Group1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:Button runat="server" Text="按我1" UseSubmitBehavior="false"
ValidationGroup="Group1" OnClientClick="disableButton(this);">
</asp:Button>
</div>
<input type="button" value="点击一次,模拟连续点击'按我1'两次" />
复制代码 代码如下:
public static int i = 0;
protected void btnPostBack_Click(object sender, EventArgs e)
{
Response.Write(((Button)sender).Text + " " + (++i).ToString());//将累加结果输出
}
&& ((validateGroup == undefined && Page_ClientValidate() == false)
|| (validateGroup != undefined && Page_ClientValidate(validateGroup) == false)))
{ //如果指定了ValidateGroup,则只验证改组;如果未指定,则验证全部验证控件
return false;
}
button.disabled = true;
return true;
}
function doubleClick()
{
var button1 = document.getElementById('btnPostBack1');
button1.onclick();
button1.onclick();
}
</script>
</head>
<body>
<form runat="server">
<div>
<asp:TextBox runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxInput1"
ValidationGroup="Group1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:Button runat="server" Text="按我1" UseSubmitBehavior="false"
ValidationGroup="Group1" OnClientClick="if(!disableButton(this, 'Group1')) return false;">
</asp:Button>
</div>
<div>
<asp:TextBox runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxInput2"
ValidationGroup="Group2" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:Button runat="server" Text="按我2" UseSubmitBehavior="false"
OnClientClick="if(!disableButton(this)) return false;">
</asp:Button>
</div>
<input type="button" value="点击一次,模拟连续点击'按我1'两次" />
</form>
</body>
</html>
新闻热点
疑难解答
图片精选