gpt4 book ai didi

jquery - 从 jQuery 对象中删除 DOM 元素

转载 作者:行者123 更新时间:2023-12-03 21:27:02 25 4
gpt4 key购买 nike

jQuery 可以轻松地从 DOM 中删除节点。但是如何从给定的 jQuery 对象中删除 DOM 元素呢?

最佳答案

如果您正在谈论从 jQuery 对象中删除节点,请使用 filternot 函数。 See here for more .

如何使用过滤器:

var ps = $('p');

//Removes all elements from the set of matched elements that do
//not match the specified function.
ps = ps.filter(function() {
//return true to keep it, false to discard it
//the logic is up to you.
});

var ps = $('p');

//Removes all elements from the set of matched elements that
//do not match the specified expression(s).
ps = ps.filter('.selector');

如何使用not:

var ps = $('p');

//Removes elements matching the specified expression
//from the set of matched elements.
ps = ps.not('.selector');

关于jquery - 从 jQuery 对象中删除 DOM 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1405128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com