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

发布于 2025-01-04 18:29:54 字数 615 浏览 5 评论 0原文

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

实际上它是一种 invination 形式,我像这样制作发送按钮

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

,这里是 css

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

所以正如您所看到的,按钮已被禁用,您无法单击,在该按钮被删除禁用后,您必须先写下您的姓名和邮件,然后才能发送邮件。 为此,我在这里编写的代码是: http://pastebin.com/8u23G90b

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

p.s 对不起我的英语

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

童话里做英雄 2025-01-11 18:29:54

删除属性:

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

请参阅 .removeAttr() 了解更多详细信息

Remove the attribute:

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

See .removeAttr() for more details

拿命拼未来 2025-01-11 18:29:54

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

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

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

:可以看到 this jsfiddle 的示例。

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.

原谅我要高飞 2025-01-11 18:29:54

尝试这样写:

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

Try to write it like that:

$('myButton').prop("disabled", "");
喵星人汪星人 2025-01-11 18:29:54

只需使用按钮即可直播:

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

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(); });
草莓酥 2025-01-11 18:29:54

我遇到了类似的问题,我使用 .prop("disabled", false) 从“保存”按钮中删除禁用状态。禁用是通过 .prop("disabled", true) 分配的。

但是等一下,当尝试删除此属性(在 html 标记中将其呈现为禁用)时,我发现它被输出为 class="disabled"!

为此 - 我使用了 .removeClass('disabled')
我想说的是,如果事情没有按照您想象的方式进行,请确保它们的初始输出符合您的预期。


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.


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文