<script type="text/javascript" language="javascript">
var btndelayId; //定时器编号
var btndelaytip = 100; //倒计时次数
function _SetTip(obj, oldvalue) {
if (obj) {
obj.disabled = true;
obj.value = "查询中";
btndelaytip--;
if (btndelayId && btndelaytip < 0) {
window.clearInterval(btndelayId);
btndelaytip = 100; ; //还原倒计时次数
obj.value = oldvalue;
obj.disabled = false;
}
}
};
function SetTip(obj, oldvalue) {
return function () {
_SetTip(obj, oldvalue);
}
};
function DoDelay(obj) {
var oldvalue = obj.value;
btndelayId = window.setInterval(SetTip(obj, oldvalue), 100); //每1/10秒更新计数
};
</script>
调用代码:
<form id="form1" runat="server">
<div>
<asp:Button ID="btnSub" runat="server" Text="查 询" Width="60" OnClientClick="DoDelay(this);" onclick="btnSub_Click" />
</div>
</form>
后台代码:
protected void btnSub_Click(object sender, EventArgs e)
{
Thread.Sleep(6000);
Response.Write("infos");
}
但是这里不能针对同一个页面的多个按钮重复使用
var btndelayId; //定时器编号
var btndelaytip = 5;//倒计时次数
谁有好的方法?
另附网上找到的防止连续点击两次按钮JS方法:
function doubleCheck(){
if (window.document.readyState != null &&
window.document.readyState != 'complete')
{
alert("正在处理,请等待!");
return false;
}
else
{
MessageClear();
return true;
}
}
在C#代码中:
this.backButton.Attributes["onClick"] = "return doubleCheck()";