JQuery enable / disable button in IE7

I use the following code to disable the submit button

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

And this code to enable it again:

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

It works fine in all browsers I tried except Internet Explorer 7. IE7 will disable the button in order, but when it is turned on again, the button is still disabled.

This button is turned on and is clickable despite the cursor and gray color:

IE7 enabled button with disabled appearance

(A colleague had the same problem with IE8, but I could not reproduce it.)

I have a workaround that does this job, but its ugliness. I have two buttons, one is disabled and one is not. To get started, I will show the disabled and hidden 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 allowed one.

Is there a more elegant CSS or JQ based solution for this problem?

+4
source share
3 answers
 $("input[type='submit']").prop("disabled", false); 
+8
source

Try

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

or

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

@Burak - This works very well (John Resig mentions this instead of using .prop () instead of .attr () for this particular case). I also tried submitbutton.prop("disabled", false); and submitbutton.prop("disabled", true); to enable and disable IE 7/6.

+1
source

Source: https://habr.com/ru/post/1369578/


All Articles