【问题标题】:CSS Select all inputs except those inside DIV containig classCSS 选择除 DIV 包含类之外的所有输入
【发布时间】:2020-11-28 15:12:45
【问题描述】:

我正在尝试禁用所有表单输入,除了那些在里面的输入

<div class="class class2 w--tab-active">...</div>

由于某种原因,这也会禁用上述输入:

$('form :input:not(.w--tab-active)').prop('disabled',true);

我也试过了:

$('form :not(.w--tab-active) :input').prop('disabled',true);

你知道怎么回事吗?

【问题讨论】:

  • 删除:not() 选择器之前的空格。也可以使用 filter 方法过滤结果:$('form input').filter('form:not(.w--tab-active input)').prop('disabled, true);

标签: html jquery css-selectors


【解决方案1】:

这对我有用:

$("form input:not('form .w--tab-active input')").each(function(){
   console.log(this);
   $(this).prop('disabled', true);
});

jsFiddle

【讨论】:

    【解决方案2】:

    使用这个:

    $('form input').not($('.w--tab-active').find('input')).prop('disabled', true);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-14
      • 2017-07-27
      • 2013-05-22
      • 2013-08-07
      • 2012-05-18
      • 1970-01-01
      • 2015-05-01
      • 2018-09-06
      相关资源
      最近更新 更多