【问题标题】:select input type next with not class selector使用非类选择器选择输入类型
【发布时间】:2020-03-23 06:51:41
【问题描述】:

我需要选择所有没有特定类的输入类型texts

这是我尝试但没有成功的方法:

$('input.text:not(.fld-required-' + val + ')').each(function() {
    $(this).val('');
});

更新
这是我没有被选中的一个输入文本:

<input placeholder="my_input" class="fld-required fld-required-1" name="my_input" type="text" required="">

【问题讨论】:

  • 您的代码应该可以工作。如果没有,那么我们需要查看相关的 HTML,以及您定义 val 的位置
  • @RoryMcCrossan 我更新了问题
  • 您在输入中没有text 类,因此您的代码将不会执行,因为它包含在具有文本类的输入中。
  • 我不需要选择“text”类的输入,而是选择“text”类型的输入
  • 那么你必须使用input[type="text"]而不是input.text

标签: jquery jquery-selectors


【解决方案1】:

您没有为您的输入元素分配text 类。

您可以使用attribute selector:

$('input[type="text"]:not(.fld-required-' + val + ')').each(function() {
    $(this).val('');
});

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 2013-11-01
    • 2017-11-21
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多