jQuery 1.2 带来的兼容问题及对策

jQuery 1.2 中抛弃了不少之前的功能,因此不能向前兼容,而有不少非官方的 jQuery 插件(比如 thickbox),使用的是 jQuery 1.2 之前的语法开发的,如果这次还未根据新版本更新的,则可能会出现问题。下面是一些新的写法,主要是关于选择器 (Selector) 的语法方面:

$("div//p") XPath Descendant Selector
Please use the CSS $("div p") selector instead. Or, use the XPath Compatibility Plugin.

$("div/p") XPath Child Selector
Please use the CSS $("div > p") selector instead. Or, use the XPath Compatibility Plugin.

$("p/../div") XPath Parent Selector
Please use the $("p").parent("div") selector instead. Or, use the XPath Compatibility Plugin.

$("div[p]") XPath Contains Predicate Selector
Please use the new $("div:has(p)") selector instead. Or, use the XPath Compatibility Plugin.

$("a[@href]") XPath Attribute Selector
Note: While this selector is deprecated, it has not yet been removed as of this release (jQuery 1.2).
It is now recommended that you use the CSS selector $("a[href]") instead. Or, use the XPath Compatibility Plugin.

另有一个 jquery.xpath.js 的插件做向前兼容,但我测试下来好像不理想,有很多会不生效。
现在比较好的做法是修改老代码中使用到 XPath Selector 的语法为 CSS Selector.

全部的更改列表需要仔细阅读 jQuery 1.2 的发布说明:
http://docs.jquery.com/Release:jQuery_1.2

这里只是我对比较重要的方面的一个摘录。

另外不能理解的就是 jQuery 为什么要把 XPath Selector 的功能分离出去。。。

posted on   NeilChen  阅读(869)  评论(3编辑  收藏  举报

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
历史上的今天:
2006-09-27 对 CSS 控件适配器处理事件的 Bug 进一步修正

导航

统计

点击右上角即可分享
微信分享提示