简体   繁体   English

jQuery xPath选择器,&&

[英]jQuery xPath selector, &&

I'm using jQuery to run through all the inputs within a section that I have set from hidden to show, and add required calsses, so as to catch the validation. 我正在使用jQuery来遍历我设置为隐藏的部分中的所有输入,并添加必需的cals,以赶上验证。

$("#" + dependant).find("input[type!='radio']").addClass('required');

Works fine, but I also want to exclude the submits. 工作正常,但我也想排除提交内容。 In normal xPath I would; 在普通的xPath中,我会;

input[type!='radio' and type!='submit'] 输入[type!='radio',然后键入!='submit']

I acheived a work around using .each() and an additional IF; 我实现了围绕.each()和附加IF的工作;

$("#" + dependant).find("input[type!='radio']").each(function()
{
    if ($(this).attr(type) != 'submit')
    {
        $(this).addClass('required')
    }
});

But it strikes me there must be an easier, cleaner way of combining contraints.... 但令我惊讶的是,必须有一种更轻松,更清洁的组合约束方法。

See Traversing and Selectors in the jQuery docs. 请参阅jQuery文档中的遍历和选择器。

$("#" + dependant).find(":input").not(':radio').not(':submit').addClass('required');

You can do: 你可以做:

$("#" + dependant).find("input[type!='radio'][type!='submit']").addClass('required');

See multiple attribute selector : 请参阅多个属性选择器

Description : Matches elements that match all of the specified attribute filters. 描述 :匹配与所有指定的属性过滤器匹配的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM