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 @ 2007-09-27 18:31 木野狐(Neil Chen) 阅读(466) 评论(3)  编辑 收藏 所属分类: 网页技术

contact us for job offer at ( sinopce_ltd001@yahoo.com.cn)
  回复  引用    
#2楼 2008-01-11 11:52 | qh [未注册用户]
希望你出一个jQuery 1.2.1的系列教学文章!
期待ing。。。。。。
  回复  引用  查看    
#3楼 [楼主]2008-01-11 17:19 | 木野狐(Neil Chen)      
@qh
sorry, 因为个人工作方面发生了一些变故, 这阶段事情比较多,尚未在计划中.

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接: