1.6 版本中的 jquery attr 行为
我已经创建了一个页面这里
1.5 版工作正常,
现在 1.6 版在 firebug 和 chrome 中都遇到此错误,
elem.getAttribute is not a function
[Break On This Error] ret = elem.getAttribute( name );
几乎相同
Uncaught TypeError: Object #<HTMLDocument> has no method 'getAttribute'
如何纠正它? 我是否必须像 jquery 1.6 api 中那样将所有内容更改为 prop http://api.jquery.com/prop/
I have made a page here
It was working fine with version 1.5
now with 1.6 i m getting this error in firebug
elem.getAttribute is not a function
[Break On This Error] ret = elem.getAttribute( name );
and in chrome almost the same
Uncaught TypeError: Object #<HTMLDocument> has no method 'getAttribute'
How do rectify it??
Do i have to change everything to prop as in jquery 1.6 api
http://api.jquery.com/prop/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在您的库
jquery.getUrlParam.js
中。它具有如下所示的行:这在 jQuery <= 1.5 下工作,因为
attr
同时使用了属性和特性。 jQuery 1.6 消除了这种混乱,这给依赖这种行为的代码带来了一些问题。这是由于更改而损坏的代码示例。更正是
你应该能够在你的代码中修复这个问题;将其报告给插件作者可能也是明智的。
进一步的一点是,当在
document
对象上尝试attr
时,jQuery 可能应该给出更好的错误消息,因为document
节点(与元素节点不同) ),没有getAttribute
方法。这就是您神秘的错误消息的原因。5 月 11 日编辑 这里的错误看起来已在 jQuery 1.6.1 中修复。 此提交到 jQuery 源意味着 jQuery 依赖于
prop 方法(如果所选节点没有
getAttribute
方法)。这与1.6.1 中的其他更改一起应该可以进行升级从<1.6到1.6.1无缝。
The problem is, I think, in your library
jquery.getUrlParam.js
. This has lines like the following:This worked under jQuery <= 1.5, because
attr
used both properties and attributes. jQuery 1.6 has cleared this confusion up, which has created some problems for code that relied on this behaviour. This is an example of code that has broken because of the change.The correction would be
You should be able to fix this in your code; it's probably also wise to report it to the plugin author.
A further point is that jQuery should probably give a better error message when trying
attr
on thedocument
object, because thedocument
node (unlike element nodes), does not have agetAttribute
method. This is the cause of your mysterious error message.Edit 11 May The error here looks like being fixed in jQuery 1.6.1. This commit to the jQuery source means that jQuery falls back on the
prop
method if the selected node does not have agetAttribute
method.This, along with the other changes in 1.6.1 should make upgrading from <1.6 to 1.6.1 seamless.