禁用按钮? [英] Disabling Buttons?
问题描述
单击按钮后如何禁用按钮?如果用户连接速度慢,我想阻止用户点击两次。
谢谢......
How can I disable a button once it has been clicked? I want to prevent
the user from clicking on it twice if they have a slow connection.
Thanks...
推荐答案
Ralph Freshour写道:
Ralph Freshour wrote:
如何点击按钮后如何禁用按钮?如果用户连接速度慢,我想阻止用户点击两次。
谢谢......
How can I disable a button once it has been clicked? I want to prevent
the user from clicking on it twice if they have a slow connection.
Thanks...
< input type =" button" value ="请点击我 class =" button"
onclick =" return singleClick(this,''Please wait ...'');" />
< script type =" text / javascript">
function singleClick(b,s){
//将焦点移开按钮
b.blur();
//已经点击了按钮?
if(typeof b.isClicked!=" undefined"&& b.isClicked){
//是的,禁止行动
返回false;
}否则{
//否,标记它已被点击
b.isClicked = true;
//我们应该更改按钮文字吗?
if(typeof s!=" undefined"){
//是的,是有支持设置按钮的宽度吗?
if(typeof b.style!=" undefined"&&
typeof b.style.width!= " undefined"&
typeof b.offsetWidth!=" undefined"){
//是的,将宽度设置为当前宽度
b.style.width = b.offsetWidth +" px";
}
//更改按钮上的文字
b.value = s;
//是否支持设置按钮的CSS类?
if(typeof b.className!=" undefined"){
//是的,将CSS类设置为buttonDisabled
//(在css中定义)
b.className =" buttonDisabled" ;;
}
}
//允许行动
返回true;
}
}
< / script>
此代码的一个重点是请等待......您传递给
的文本按钮*必须*比当前文本短。延长时间将使b / b
使程序复杂化。或者,您可以完全处理
更改文本和className,因为它只是
化妆品。
-
| Grant Wagner< gw ***** @ agricoreunited.com>
*客户端Javascript和Netscape 4 DOM参考可从以下位置获得:
*
http:// devedge .netscape.com / library / ... ce / frames.html
* Internet Explorer DOM参考资料:
*
http://msdn.microsoft.com/研讨会/ a ... ence_entry.asp
* Netscape 6/7 DOM参考资料于:
* http://www.mozilla.org/docs/dom/domref/
*为Netscape 7 / Mozilla升级JavaScript的提示
* http://www.mozil la.org/docs/web-deve...upgrade_2.html
<input type="button" value="Please click me" class="button"
onclick="return singleClick(this, ''Please wait...'');" />
<script type="text/javascript">
function singleClick(b, s) {
// move focus off the button
b.blur();
// has the button already been clicked?
if (typeof b.isClicked != "undefined" && b.isClicked) {
// yes, disallow the action
return false;
} else {
// no, flag that it has been clicked
b.isClicked = true;
// should we change the button text?
if (typeof s != "undefined") {
// yes, is there support to set the width of a button?
if (typeof b.style != "undefined" &&
typeof b.style.width != "undefined" &&
typeof b.offsetWidth != "undefined") {
// yes, set the width to the current width
b.style.width = b.offsetWidth + "px";
}
// change the text on the button
b.value = s;
// is there support to set the CSS class of a button?
if (typeof b.className != "undefined") {
// yes, set the CSS class to "buttonDisabled"
// (defined in css)
b.className = "buttonDisabled";
}
}
// allow the action
return true;
}
}
</script>
One important point with this code, the "Please wait..." text you pass to
the button *must* be shorter then the current text. Making it longer would
significantly complicate the procedure. Alternatively, you could dispose
of changing the text and the className entirely, since it''s all just
cosmetic.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
" Grant Wagner" < GW ***** @ agricoreunited.com>在消息中写道
新闻:3F ************** @ agricoreunited.com ...
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:3F**************@agricoreunited.com...
Ralph Freshour写道:
Ralph Freshour wrote:
单击按钮后如何禁用按钮?如果用户连接速度慢,我想阻止用户点击两次。
谢谢......
How can I disable a button once it has been clicked? I want to prevent
the user from clicking on it twice if they have a slow connection.
Thanks...
<输入类型=”按钮" value ="请点击我 class =" button">
... snip ...
<input type="button" value="Please click me" class="button">
... snip ...
或:
< ; html>
< body>
< form id =" MyForm" ACTION =" http://example.microsoft.com/sample.asp"
METHOD =" POST">
< input type =" submit" ; value =" Press Me"
onclick =" this.disabled = true; document.all.MyForm.su bmit();">
< / input>
< form>
< / body>
< / html>
问候,
克里斯。
Or:
<html>
<body>
<form id="MyForm" ACTION="http://example.microsoft.com/sample.asp"
METHOD="POST">
<input type="submit" value="Press Me"
onclick="this.disabled=true;document.all.MyForm.su bmit();">
</input>
<form>
</body>
</html>
Regards,
Chris.
Chris a ecrit:
Chris a ecrit :
Grant Wagner < GW ***** @ agricoreunited.com>在消息中写道
新闻:3F ************** @ agricoreunited.com ...
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:3F**************@agricoreunited.com...
Ralph Freshour写道:
Ralph Freshour wrote:
> onclick =" this.disabled = true; document.all.MyForm.su bmit();">
onclick="this.disabled=true;document.all.MyForm.su bmit();">
beuark!这是IE的! (和其他人他们做了什么?)
beuark ! that''s for IE ! ( and others what do they do ? )
这篇关于禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!