jQuery .prop(“disabled”, false) not working in Chrome

删除回忆录丶 提交于 2019-12-08 14:36:19

问题


having problems with .prop("disabled", false) it's works fine in opera and firefox but IE and chrome i can't get it to work..

Actualy it's a invination form and im make send button like this

<input id="sendInvite" class="mail_send" disabled="disabled" type="button" name="invite" value="Send">

and here is css

.mail_send[disabled="disabled"] {background-color:#343434; color:#747474}

So as you can see button is disabled and you can't click, you must first write your name and mail after that button is remove disabled and you can send mail. For this im write code here is: http://pastebin.com/8u23G90b

But something is wrong here, in chrome and IE disabled never removed from button, im also load jquery 1.7.1

p.s sorry for my english


回答1:


Remove the attribute:

$('button').removeAttr("disabled");

See .removeAttr() for more details




回答2:


Your problem is not with JQuery, but with your CSS selectors. The disabled attribute is referring to the default value when the page first loads, rather than whether the element is actually disabled or not.

The CSS selector you want is the :disabled selector:

.mail_send:disabled {background-color:#343434; color:#747474}

You can see an example with this jsfiddle.




回答3:


I was running into a similar issue where I was using .prop("disabled", false) to remove disabled from a 'Save' button. Disabled was being assigned via .prop("disabled", true).

But wait who what - when trying to remove this property (which would be rendered as disabled in the html tag) I discovered that it was being output as class="disabled"!

For this - i used .removeClass('disabled') All i'm trying to say is if things don't work the way you think they should, make sure their initial output is what you'd expect.





回答4:


Try to write it like that:

$('myButton').prop("disabled", "");



回答5:


just use button and live:

<button class="sendm">Send Email</button>

$(".sendm").live("click", function(e){
   var field1 = $("").val();
   var field2 = $("").val();

   if(field1 === "" || field2 === "" ){
    /// fake checker, you make this more robust etc
     return false;  // maybe do an alert here
   } else {
      //post form data and get json response
   }

});

 $(document).ready(function(){ $(".sendm").button(); });


来源:https://stackoverflow.com/questions/9240439/jquery-propdisabled-false-not-working-in-chrome

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