【问题标题】:How to remove disable element using JQUERY? [duplicate]如何使用 JQUERY 删除禁用元素? [复制]
【发布时间】:2017-12-10 09:22:09
【问题描述】:

我使用jQuery 1.8.3

这是我的html输入文本框:

<input type="text" name="textinput-hide" id="textinput1" placeholder="Text input" value="" disabled>

这是我尝试删除禁用元素的方法:

  $('#textinput1').removeProp('disabled');

但上面的行并没有删除disabled 属性。如何删除禁用元素

【问题讨论】:

  • 您要删除具有禁用属性的属性或完整元素吗?
  • $('#textinput1').removeAttr('disabled');
  • $('#textinput1').remove();
  • 这个链接可能对你有帮助..stackoverflow.com/questions/13626517/…
  • 以下是 jQuery 关于removeProp 的说法:不要使用此方法删除本机属性,例如选中、禁用或选中。这将完全删除该属性,并且一旦删除,就不能再次将其添加到元素中。使用 .prop() 将这些属性设置为 false。

标签: javascript jquery


【解决方案1】:

如果你想删除disable属性:-

$('input').each(function(){
  if($(this).prop("disabled")){
    $(this).prop("disabled", false);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="textinput-hide" id="textinput1" placeholder="Text input1" value="" disabled><br><br>

<input type="text" name="textinput-hide" id="textinput2" placeholder="Text input2" value="">

如果你想删除整个元素本身:-

$('input').each(function(){
  if($(this).prop("disabled")){
    $(this).remove();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" name="textinput-hide" id="textinput1" placeholder="Text input1" value="" disabled><br>

<input type="text" name="textinput-hide" id="textinput2" placeholder="Text input2" value="">

【讨论】:

  • 我试试这个 $('#textinput1').prop("disabled", false);但它不起作用
  • @Michael 在我的代码中工作。所以我不明白为什么它对你不起作用。为你的问题创建一个小提琴示例,我会纠正它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
  • 2011-10-24
相关资源
最近更新 更多