jQuery .attr("disabled", "disabled") 在 Chrome 中不起作用 [英] jQuery .attr("disabled", "disabled") not working in Chrome

查看:98
本文介绍了jQuery .attr("disabled", "disabled") 在 Chrome 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道为什么这不起作用.

当人们点击我的应用程序的编辑"按钮时,被禁用的文本字段变得可

$("#bewerken").click(function(e) {$("input[disabled='disabled']").removeAttr('disabled');});

然后我想在用户保存时再次禁用文本字段;我将此代码绑定到我的保存按钮:

$("#save_school_changes").click(function(e) {//东西$.ajax({类型:POST",url: "/school/save_changes",数据:{//东西},成功:功能(数据){$("#feedback_top").html("<p>" + data['message'] + "</p>").slideDown('slow').delay(2000).slideUp();$("input[type='text']").attr('disabled', 'disabled');}});e.preventDefault();});

据我所知,这应该会再次禁用文本字段.但是,这似乎不适用于 Chrome.它确实在 Firefox 中工作.我还没有机会在 IE 或 Safari 中进行测试.有什么办法可以在 Chrome 中进行这项工作吗?非常感谢!

解决方案

如果您正在使用 jQuery

1.6这样做:

jQuery("input[type='text']").attr("disabled", 'disabled');

如果您使用的是 jQuery 1.6+:

jQuery("input[type='text']").prop("disabled", true);

请参阅此问题:.prop() vs .attr() 以了解原因.>

或者你可以试试这个:

$('input:text').attr("disabled", 'disabled');

查看此处了解关于 :text

Not sure why this isn't working.

When people click the 'edit' button of my application, the disabled textfields become editable:

$("#bewerken").click(function(e)    {
    $("input[disabled='disabled']").removeAttr('disabled');
});

I then want to disable the textfields again when the user saves; I have this code bound to my save button:

$("#save_school_changes").click(function(e) {
    //stuff

    $.ajax({
        type: "POST",
        url: "/school/save_changes",
        data: { //stuff },
        success: function(data)
        {
            $("#feedback_top").html("<p>" + data['message'] + "</p>").slideDown('slow').delay(2000).slideUp();
            $("input[type='text']").attr('disabled', 'disabled');

        }
    });

    e.preventDefault();
});

As far as I know, this should disable the textfields again. However, this does not seem to be working in Chrome. It does work in Firefox. I haven't had the chance to test in IE or Safari yet. Is there any way to make this work in Chrome aswell? Thanks a lot!

解决方案

If you are using jQuery < 1.6 do this:

jQuery("input[type='text']").attr("disabled", 'disabled');

If you are using jQuery 1.6+:

jQuery("input[type='text']").prop("disabled", true);

See this question: .prop() vs .attr() for references why.

Or you can try this:

$('input:text').attr("disabled", 'disabled');

see here for info on :text

这篇关于jQuery .attr("disabled", "disabled") 在 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆