sizzle分析记录:getAttribute和getAttributeNode
生活随笔
收集整理的這篇文章主要介紹了
sizzle分析记录:getAttribute和getAttributeNode
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
部分IE游覽器下無法通過getAttribute取值?
<form name="aaron"> <input type="text" name="aaron"/> </form> alert(form.getAttribute('name')); IE6、7中錯誤 alert(form.getAttributeNode('name').nodeValue);看看jQ的解決方案
能力判斷
support.attributes = assert(function( div ) {div.className = "i"; //設置一個屬性return !div.getAttribute("className"); });處理
Sizzle.attr = function( elem, name ) {return val !== undefined ?val :support.attributes || !documentIsHTML ?elem.getAttribute( name ) :(val = elem.getAttributeNode(name)) && val.specified ?val.value :null; };使用getAttributeNode得到屬性節點,再通過nodeValue得到該屬性節點的值
getAttributeNode的效率比getAttribute要低一些。如果要獲取元素的id,node.id是最快的方法,node.getAttribute('id')其次,getAttributeNode('id').nodeValue最慢。
轉載于:https://www.cnblogs.com/aaronjs/p/3837082.html
總結
以上是生活随笔為你收集整理的sizzle分析记录:getAttribute和getAttributeNode的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Technical news July-
- 下一篇: Swift游戏实战-跑酷熊猫 00 游戏