【问题标题】:jquery attr behaviour in version 1.61.6 版中的 jquery attr 行为
【发布时间】:2011-08-21 11:47:52
【问题描述】:

我已经做了一个页面here

在 1.5 版中运行良好

现在 1.6 我在 firebug 中遇到这个错误

 elem.getAttribute is not a function
 [Break On This Error] ret = elem.getAttribute( name ); 

和chrome几乎一样

 Uncaught TypeError: Object #<HTMLDocument> has no method 'getAttribute'

如何改正?? 我是否必须像在 jquery 1.6 api 中那样更改所有内容以支持 http://api.jquery.com/prop/

【问题讨论】:

标签: jquery attributes prop


【解决方案1】:

我认为问题在于您的图书馆jquery.getUrlParam.js。这有如下几行:

if ($(this).attr("nodeName")=="#document") {

这在 jQuery attr 同时使用了属性和属性。 jQuery 1.6 消除了这种混乱,这给依赖这种行为的代码带来了一些问题。这是一个因更改而损坏的代码示例。

修正是

if (this.nodeName === "#document") {

您应该能够在您的代码中解决此问题;将其报告给插件作者可能也是明智之举。

更进一步的一点是,当在document 对象上尝试attr 时,jQuery 可能会给出更好的错误消息,因为document 节点(与元素节点不同)没有getAttribute 方法。这就是您出现神秘错误消息的原因。


5 月 11 日编辑 这里的错误看起来在 jQuery 1.6.1 中已修复。 This commit 到 jQuery 源意味着如果所选节点没有 getAttribute 方法,则 jQuery 回退到 prop 方法。

这与the other changes in 1.6.1 一起应该可以无缝地从

【讨论】:

  • 是的,它做到了...感谢您的帮助...是一个笨重的库,虽然我没有使用它...
  • 你认为这是一个 bug 还是 jquery 的改进...虽然我不知道...;-)
猜你喜欢
  • 2016-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 2011-06-25
相关资源
最近更新 更多