JQuery 在 IE7 中启用/禁用提交按钮
我使用以下代码来禁用提交按钮
$("input[type='submit']").attr("disabled", "disabled");
,并使用此代码重新启用它:
$("input[type='submit']").removeAttr("disabled");
它在我尝试过的所有浏览器上都可以正常工作,除了 Internet Explorer 7。IE7 将很好地禁用该按钮,但是当它重新启用时,该按钮看起来仍然处于禁用状态。
尽管光标和灰色颜色,此按钮仍处于启用状态并可单击:
(一位同事有IE8 也有同样的问题,但我无法重现它。)
我有一个解决方法可以完成这项工作,但它很难看。我有两个按钮,一个禁用,一个不禁用。首先,我显示禁用的按钮并隐藏启用的按钮。
$("input[type='submit']:first").css("display","inline"); //show disabled
$("input[type='submit']:last").css("display","none"); //hide enabled
...
<input name="Submit" type="submit" value=" Sign In " tabindex=3 disabled>
<input name="Submit" type="submit" value=" Sign In " tabindex=3 >
当满足我的“if”条件时,我会隐藏禁用的提交并显示启用的提交。
是否有更优雅的 CSS 或基于 JQ 的解决方案来解决这个问题?
I am using the following code to disable the submit button
$("input[type='submit']").attr("disabled", "disabled");
And this code to re-enable it:
$("input[type='submit']").removeAttr("disabled");
It works fine on all browsers I've tried except Internet Explorer 7. IE7 will disable the button fine, but when it is re-enabled, the button still looks disabled.
This button is enabled and clickable in spite of the cursor and gray color:
(A colleague had the same trouble with IE8, but I could not reproduce it.)
I have a workaround in place that does the job, but its ugly. I have two buttons, one disabled, one not. To start, I show the disabled one and hide the enabled button.
$("input[type='submit']:first").css("display","inline"); //show disabled
$("input[type='submit']:last").css("display","none"); //hide enabled
...
<input name="Submit" type="submit" value=" Sign In " tabindex=3 disabled>
<input name="Submit" type="submit" value=" Sign In " tabindex=3 >
When my "if" conditions are met, I hide the disabled submit and show the enabled one.
Is there a more elegant CSS or JQ based solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Burak - 这非常有效(John Resig 确实提到在这个特定情况下使用 .prop() 而不是 .attr() )。我还尝试了
submitbutton.prop("disabled", false);
和submitbutton.prop("disabled", true);
这样就可以在 IE 7 上启用和禁用/6 也是如此。@Burak - That works very well (John Resig does mention about it of using .prop() instead of .attr() for this specific case). I also tried the
submitbutton.prop("disabled", false);
andsubmitbutton.prop("disabled", true);
so that would enable and disable on IE 7/6 as well.尝试
或
Try
or