JQuery Enable / Disable Submit Button in IE7

空扰寡人 提交于 2019-12-06 05:39:51

问题


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?


回答1:


$("input[type='submit']").prop("disabled", false);



回答2:


Try

$("input[type='submit']").attr("disabled", "");

or

$("input[type='submit']").attr("disabled", false);



回答3:


@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); and submitbutton.prop("disabled", true); so that would enable and disable on IE 7/6 as well.



来源:https://stackoverflow.com/questions/7236727/jquery-enable-disable-submit-button-in-ie7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!