百度空间 | 百度首页 
 
查看文章
 
Firefox 也有严重不靠谱的事情
2009-06-04 20:53
var doc = new DOMParser().parseFromString("<xml/>","text/xml");
el = doc.documentElement;

alert(el.getAttribute("none") == "")

期待的输出是 true
可结果确是 false

因为他获取没有的属性返回的是 null

这就是问题了,w3c dom 标准明明规定是返回空字符串的嘛??

FF也不听话了?

看来可恶的w3c让狐狸都发飙了,呵呵



类别:默认分类 | 添加到搜藏 | 浏览() | 评论 (1)
 
最近读者:
 
网友评论:
2
2009-06-11 08:21 | 回复
属性名称不存在时,最好先用hasAttribute检测下:
Essentially all web browsers (Firefox, Internet Explorer, recent versions of Opera, Safari, Konqueror, and iCab, as a non-exhaustive list) return null when the specified attribute does not exist on the specified element. The DOM specification says that the correct return value in this case is actually the empty string, and some DOM implementations implement this behavior. The implementation of getAttribute in XUL (Gecko) actually follows the specification and returns an empty string. Consequently, you should use hasAttribute to check for an attribute's existence prior to calling getAttribute() if it is possible that the requested attribute does not exist on the specified element.
链接:https://developer.mozilla.org/en/DOM/element.getAttribute#Notes
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu