功能在 windows 的 safari 中不起作用

Function doesn't work in safari on windows

虽然此语法适用于所有其他浏览器,但 windows 上的 Safari 会抛出错误

$("#kibana").contents().find('.navbar-nav')[0].remove();

错误是

TypeError: 'undefined' is not a function 

该元素确实存在。我使用调试器进行了检查。

为什么会这样?

当您在 jQuery 对象上使用 [] 时,您正在检索基础 DOM 节点。 .remove 在本机 DOM 元素上不完全跨浏览器兼容。

相反,您可以使用 .eq to retrieve the element while still having it wrapped in jQuery. That way you can use the cross-browser comptabile .remove 方法:

$("#kibana").contents().find('.navbar-nav').eq(0).remove();