【问题标题】:Opposite of jQuery .parents() selector [duplicate]与 jQuery .parents() 选择器相反 [重复]
【发布时间】:2014-10-24 20:12:39
【问题描述】:

我正在为页面制作用户脚本。该页面是老式的桌子 - 无处不在的设计。我正在尝试访问长字段表,以便它们可以被脚本填充。

结构可以简化成这样:

<form>
  <blockquote>
    <table>
      <tr>
        <td>
           <table>
              <!-- THE DESIRED <input> FIELDS ARE HERE!! -->
           </table>
        </td>
        <td>
            <table>
               <!-- Contains <select> <input> -->
            </table>
        </td>
      </tr>
    </table>
    <!-- the table repeats and I need all inner tables -->
  </blockquote>
</form>

所以我想我可以获得form table 中的所有表,但不包含 &lt;select&gt;

我认为parents selector in jQuery 的对面是理想的。有这样的东西吗?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    你可以试试

    $('form table table').not(':has(select)');
    

    form table table 选择form table 中的所有表,然后我们排除具有select 元素的项目

    【讨论】:

    • 干得好,有效!
    • 甚至$('form table table:not(:has(select))'); ?
    【解决方案2】:
    $('form table table').each(function(){
        if($(this).find('select').size()==0){
         //do something
        }
     });
    

    另一种方法。

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 2018-08-16
      • 2021-09-17
      • 1970-01-01
      • 1970-01-01
      • 2013-05-27
      相关资源
      最近更新 更多