XPath 还是 querySelector?

XPath or querySelector?(XPath 还是 querySelector?)
本文介绍了XPath 还是 querySelector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

XPath 可以做所有 querySelector 可以做的事情,甚至更多,那么你什么时候会选择后者呢?我还没有看到任何速度基准比较这两者,所以现在我根据语法简洁性进行选择,这似乎有点随意.

XPath can do everything querySelector can do, and more, so when would you ever choose the latter? I haven't seen any speed benchmarks comparing the two, so right now I'm choosing based on syntax conciseness, which seems kind of arbitrary.

我可能应该说我正在为 Firefox 编写 Greasemonkey 脚本,所以我不担心跨浏览器的兼容性,并且宁愿不包含任何库.

I probably should have stated that I'm writing Greasemonkey scripts for Firefox, so I'm not worried about cross-browser compatibility, and would rather not include any libraries.

推荐答案

你用的是什么浏览器?在 Safari(或 iPhone)中,querySelector 和 querySelectorAll 比 XPath 快得多.IE 根本不支持 XPath,IE6 和 IE7 也不支持 querySelector.最快的跨浏览器选择器引擎是由 John Resig 创建的 Sizzle.Sizzle 也是 jQuery 中使用的主要选择器引擎.它在适当的地方使用 querySelector,在 querySelector 不可用的地方使用普通的 DOM 方法.

What browser are you using? In Safari (or the iPhone), querySelector and querySelectorAll are much faster than XPath. IE doesn't support XPath at all, and IE6 and IE7 don't support querySelector. The fastest cross-browser selector engine is Sizzle, created by John Resig. Sizzle is also the main selector engine used in jQuery. It uses querySelector where appropriate and normal DOM methods where querySelector is unavailable.

这篇关于XPath 还是 querySelector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
Check if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)