如何删除使用jQuery(IE)disabled属性 [英] How to remove disabled attribute with jQuery (IE)

查看:123
本文介绍了如何删除使用jQuery(IE)disabled属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个情况下,我必须使用禁用的属性来停用所有的投入,我不希望用户编辑。

I'm in a situation where I have to use the disabled attribute to deactivate all inputs I don't want the user to edit.

<input disabled="<%= disableInputs%>" type="text"></input>

这使得

<input disabled="False" type="text"></input>

<input disabled="True" type="text"></input>

这适用于Chrome和FF罚款,但在IE上它没有。

This works fine on Chrome and FF, but on IE it does not.

现在我试图删除这些属性(其中残疾=FALSE)使用javascript,但我没有得到预期的结果。 Againt,它的JavaScript作品GOR Chrome和FF,但不是IE浏览器(使用8)。

Now I'm trying to remove those attributes (where disabled="False") with javascript, but I don't get the expected results. Againt, it the javascript works gor Chrome and FF, but not for IE (using 8).

在结束它应该看起来像:

at the end it should look like:

<input type="text"></input>

<input disabled="True" type="text"></input>

我的JavaScript看起来像(我试过几乎所有的组合):

my javascript looks like (i've tried almost any combination):

$('document').ready(function () {

$("input[disabled='false']").each(function(){$(this).attr('disabled', false);});
$("select[disabled='false']").each(function(){$(this).attr('disabled', false);});
$("input[disabled='False']").each(function(){$(this).attr('disabled', false);});
$("select[disabled='False']").each(function(){$(this).attr('disabled', false);});
$("input[readonly='false']").each(function(){$(this).attr('readonly', false);});
$("select[readonly='false']").each(function(){$(this).attr('readonly', false);});
$("input[readonly='False']").each(function(){$(this).attr('readonly', false);});
$("select[readonly='False']").each(function(){$(this).attr('readonly', false);});

$("input[disabled='false']").each(function(){$(this).removeAttr('disabled');});
$("select[disabled='false']").each(function(){$(this).removeAttr('disabled');});
$("input[disabled='False']").each(function(){$(this).removeAttr('disabled');});
$("select[disabled='False']").each(function(){$(this).removeAttr('disabled');});
$("input[readonly='false']").each(function(){$(this).removeAttr('readonly');});
$("select[readonly='false']").each(function(){$(this).removeAttr('readonly');});
$("input[readonly='False']").each(function(){$(this).removeAttr('readonly');});
$("select[readonly='False']").each(function(){$(this).removeAttr('readonly');});
});

在一个活生生的例子:
http://jsfiddle.net/2LNa6/ 更新时间:

推荐答案

您应该使用.prop方法jQuery的因为它健全检查你绕开这些恼人的IE错误。我可以向您正在使用jQuery 1.6,所以这应该看到:

You should use the .prop method in jQuery as it does sanity checking for you bypassing these annoying IE errors. I can see you're using jQuery 1.6, so this should work:

$('document').ready(function () {
    //get each input that is disabled
    $('input').each(function(i, el){
      //see if it should be disabled (true|false)
      var disabled = $(el).data('disabled');
      $(el).prop('disabled', disabled);
    });
});

下面是更新的jsfiddle 给你看。

这篇关于如何删除使用jQuery(IE)disabled属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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