zoukankan      html  css  js  c++  java
  • 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最慢。

  • 相关阅读:
    进程的常用方法
    进程创建&僵尸进程&孤儿进程
    进程基础
    操作系统的发展史
    UDP协议&socketserver模块
    socket套接字
    简述计算机网络
    day 7-8 协程
    __new__和__init__的区别
    day 7-22 进程,线程,协程
  • 原文地址:https://www.cnblogs.com/aaronjs/p/3837082.html
Copyright © 2011-2022 走看看