例如,对于给定的 jquery 片段,等效的 javascript 应该是什么。 JavaScript 中的等效 add 方法可能会有所帮助。
$("h1").add("span").add("h2");
正如 jquery 文档中明确提到的那样 - .add()
不会添加任何 DOM 元素。 https://api.jquery.com/add/因此,使用 .appendChild()
在这里不起作用
最佳答案
文档位于https://api.jquery.com/add说
"Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. ".
该方法不执行任何 DOM 操作,它纯粹用于操作 jQuery 对象。据我所知,没有直接的等价物 - 如果您不使用 jQuery,那么根据定义,您无法创建或操作 jQuery 对象。
附注您始终可以检查该方法的 jQuery 源代码以了解它的作用。
关于javascript - jquery 中 .add() 的等效 javascript 函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52295545/