使用 javascript & 设计按钮样式客户端点击时
我的网页上有一个 asp.net 按钮。
OnClientClick 代码禁用该按钮,以便用户不能多次提交。 它还将按钮的文本更改为“请稍候...”
到目前为止一切顺利!
问题是,因为它被禁用,“请稍候...”文本看起来很垃圾... 我如何设置按钮的样式,以便即使它被禁用,它看起来仍然在 javascript 中启用。
<script type="text/javascript">
function btnSubmit_ClientClick(Client) {
var ok = Page_ClientValidate();
if (ok) {
Client.style.color = 'White';
Client.style.backgroundColor = '#9A4D9E';
Client.value = 'Please wait...';
Client.disabled = true;
}
}
</script>
编辑开始:
这是启用的按钮:
这是禁用的按钮:
...如您所见,文本是灰色和白色的?
为了进一步清晰起见,@user503034 建议在 CSS 中使用 [disabled]。 这是我的代码,但我仍然遇到同样的问题:
button[disabled]:active, button[disabled], input[type="reset"][disabled]:active, input[type="reset"][disabled], input[type="button"][disabled]:active, input[type="button"][disabled], select[disabled] > input[type="button"], select[disabled] > input[type="button"]:active, input[type="submit"][disabled]:active, input[type="submit"][disabled]
{
color: Green;
background-color: #9A4D9E;
cursor: default;
}
I have an asp.net button on a web page.
The OnClientClick code disables the button so that the user cannot submit more than once.
It also changes the text of the button to "Please wait..."
All good so far!
Trouble is, because it is getting disabled the "Please wait..." text looks rubbish...
How can I style the button so that even though it is disabled, it looks enabled, within javascript.
<script type="text/javascript">
function btnSubmit_ClientClick(Client) {
var ok = Page_ClientValidate();
if (ok) {
Client.style.color = 'White';
Client.style.backgroundColor = '#9A4D9E';
Client.value = 'Please wait...';
Client.disabled = true;
}
}
</script>
Start of Edit:
Here's the enabled button:
and here's the disabled button:
... as you can see the text is kind of grey and white?
For further clarity @user503034 suggested using [disabled] in the CSS.
Here's my code, however I still have the same issue:
button[disabled]:active, button[disabled], input[type="reset"][disabled]:active, input[type="reset"][disabled], input[type="button"][disabled]:active, input[type="button"][disabled], select[disabled] > input[type="button"], select[disabled] > input[type="button"]:active, input[type="submit"][disabled]:active, input[type="submit"][disabled]
{
color: Green;
background-color: #9A4D9E;
cursor: default;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以试试这个
这不会完全禁用该按钮,但不会让您单击它。现在您可以按照自己想要的方式设计它。如果这是表单上的提交按钮,您还可以在表单上执行 onSubmit 并在那里返回 false,以防止有人只是按 Tab 键并按 Enter 键。可能不完全是您正在寻找的东西,但它确实可以完成工作。
如果您想禁用该按钮并在之后设置其样式,请使用 user503034 的建议进行一项额外的更改,而不是仅在 CSS 中执行 [disabled],而是执行 input[disabled="disabled"], input.disabled 即可跨所有主要浏览器。
You can try this
This will not disable the button completely, but it will not let you click it. Now you can style it any way you want to. If this is submit button on the form, you can also do onSubmit on the form and return false there as well, to prevent somebody just tabbing and hitting enter key. Might not be exactly what you are looking for, but it does the job.
If you want to disable the button and style it after that, use the suggestion from user503034 with one additional change, instead of just doing [disabled] in the CSS, do input[disabled="disabled"], input.disabled that will work across all major browsers.
也许这就是您正在寻找的。
Maybe that is what you are looking for.