jQuery .prop("disabled", false) 在 Chrome 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9240439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:32:31  来源:igfitidea点击:

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

jqueryprop

提问by user994461

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..

.prop("disabled", false) 有问题,它在歌剧和火狐中工作正常,但 IE 和 chrome 我无法让它工作..

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

实际上这是一个invination表格,我制作了这样的发送按钮

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

and here is css

这是 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

所以你可以看到按钮被禁用并且你不能点击,你必须先写下你的名字和邮件,然后在按钮被禁用后才能发送邮件。为此,我在这里编写代码: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

但是这里出了点问题,在 chrome 和 IE 中禁用从未从按钮中删除,我还加载了 jquery 1.7.1

p.s sorry for my english

ps对不起我的英语

回答by J. Holmes

Remove the attribute:

删除属性:

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

See .removeAttr()for more details

有关更多详细信息,请参阅.removeAttr()

回答by Fiddles

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

您的问题不在于 JQuery,而在于您的 CSS 选择器。disabled属性指的是页面第一次加载时的默认值,而不是元素是否实际被禁用。

The CSS selector you want is the :disabled selector:

你想要的 CSS 选择器是:disabled 选择器

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

You can see an example with this jsfiddle.

你可以看到这个 jsfiddle的例子。

回答by DGG

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).

我遇到了类似的问题,我使用 .prop("disabled", false) 从“保存”按钮中删除禁用。禁用是通过 .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"!

但是等等,当我试图删除这个属性(它会在 html 标签中被呈现为禁用)时,我发现它被输出为 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.

为此 - 我使用了 .removeClass('disabled') 我想说的是,如果事情不像你认为的那样工作,请确保他们的初始输出是你所期望的。



回答by Julien Pires

Try to write it like that:

试着这样写:

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

回答by davethecoder

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(); });