Javascript 有没有办法从jQuery对象选择中删除项
我不确定我在这里是否使用了好的术语,但这就是我想要做的:Javascript 有没有办法从jQuery对象选择中删除项,javascript,jquery,Javascript,Jquery,我不确定我在这里是否使用了好的术语,但这就是我想要做的: var selection1 = jQuery('someitems'), selection2 = jQuery('someotheritemswhichcanbethesameornot'); selection2.each(function() { // if this item has some specifications (like a specific value or else), // we do
var selection1 = jQuery('someitems'),
selection2 = jQuery('someotheritemswhichcanbethesameornot');
selection2.each(function() {
// if this item has some specifications (like a specific value or else),
// we do something on it and it does not belong in selection1 anymore
// => can I remove it from selection1 ?
});
我使用jQuery选择了一组项,比如jQuery('some-items-selected-with-class-or-else')代码>,然后我正在处理其他一组项(其中一些项可以在两个“束”中),如jQuery('some-other-items-selected-with-class-or-else')代码>
我的问题是:有没有办法从第一个选项中删除第二个选项的某些项目?
如果有帮助的话,我正在使用jQuery.each()
处理第二个选择的每个项目
这就是我想做的:
var selection1 = jQuery('someitems'),
selection2 = jQuery('someotheritemswhichcanbethesameornot');
selection2.each(function() {
// if this item has some specifications (like a specific value or else),
// we do something on it and it does not belong in selection1 anymore
// => can I remove it from selection1 ?
});
谢谢您有两种方法可以做到这一点:
1) 使用以下选项缩小您的选择范围:
2) 使用以下公式减去某些元素:
示例在哪里?在没有看到HTML的情况下,这是一个猜测,但请尝试$('select.class:not(“.otherclass”)代码>我改变了问题,希望它更容易理解:这不是关于类:)在这种情况下,您可以使用filter()
,但这取决于您的用例,这是最好的方法。这就是为什么我们要求你的HTML和一个具体的例子的问题。
jQuery('select.general-class').not('.not-you');