场景:
var jsCancel = document.getElementById('js-cancel');
jsCancel.remove();
原始问题:我假设浏览器将使用 jQuery 来删除该元素。这是正确的吗?为什么?
更新的问题: Internet Explorer 不支持 ChildNode.remove()。我假设浏览器将由 jQuery 指导,当它遇到 .remove() 时应该采取什么操作。对于支持 ChildNode.remove() 的浏览器,他们是先引用 jQuery 还是跳过它直接使用 DOM API?
I'm assuming the browser will use jQuery to remove the element
不,这是完全错误的。
浏览器永远不会“使用 jQuery”。 jQuery 是一个为用户编写的库,位于普通 JavaScript 和 DOM API 之上。
jQuery 将使用 DOM API,反之亦然。
回复:您的更新
Internet Explorer does not support ChildNode.remove()
. I'm assuming the browser will be guided by jQuery on what action should occur when it encounters .remove()
再说一遍,这是完全错误的。
如果您直接使用 DOM API,则 jQuery绝对不参与。它根本不执行任何功能,除非您实际上使用它作为 DOM 的接口(interface)。它无法“引导”浏览器执行任何操作,除非您实际上使用 jQuery。如果您直接访问 DOM API,您就是有意识地选择回避 jQuery。
在 IE 中发生的情况就是您会遇到异常,并且您的页面可能会死掉。
For the browsers that support ChildNode.remove(), do they reference jQuery first or skip it and go straight to the DOM API?
不,这没有任何意义。当您调用 ChildNode.remove()
时,您已经直接进入 DOM API。如果您已经访问过“jQuery 或跳过它并直接访问 DOM API”,浏览器无法选择是否使用“jQuery 或跳过它并直接访问 DOM API”。完成了。
Tôi là một lập trình viên xuất sắc, rất giỏi!