var nodes = document.getElementsByTagName("script");
var node = nodes[nodes.length - 1];
var src = document.querySelector ? node.src : node.getAttribute("src", 4);

以前一直以为 node.getAttribute("src", 4) 是笔误,后面在MSDN中找到了对应IE中的API[1],

才明白这种写法是兼容IE的写法。

getAttribute method
Retrieves the value of the specified attribute.
Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
Syntax object.getAttribute(strAttributeName, lFlags)
Parameters strAttributeName [in]
Type: String
String that specifies the name of the attribute.
lFlags [in, optional]
Type: Integer
Integer that specifies one or more of the following flags:
0
Default. Performs a property search that is not case-sensitive, and returns an interpolated value if the property is found.
1
Performs a case-sensitive property search. To find a match, the uppercase and lowercase letters in strAttributeName must exactly match those in the attribute name.
2
Returns attribute value as a String. This flag does not work for event properties.
4
Returns attribute value as a fully expanded URL. Only works for URL attributes.
Return value Type: Variant
Variant that returns a String, Variant of type Integer, or Boolean value as defined by the attribute. If the attribute is not present, this method returns null.

[1] http://msdn.microsoft.com/en-us/library/ie/ms536429(v=vs.85).aspx

javascript getAttribute的更多相关文章

  1. HtmlAgilityPack 学习和笔记

    介绍: http://www.cnblogs.com/bomo/archive/2013/01/28/2879361.html 实战 c#获取外网ip 网址:http://ip138.com/ 如图: ...

  2. Javascript进阶篇——(DOM—getAttribute()、setAttribute()方法)—笔记整理

    getAttribute()方法通过元素节点的属性名称获取属性的值.语法: elementNode.getAttribute(name) 1. elementNode:使用getElementById ...

  3. Javascript中 a.href 和 a.getAttribute('href') 结果不完全一致

    今天无意中发现这个么问题,页面上对所有A标签的href属性为空的自动添加一个链接地址,结果发现if判断条件始终都没生效,莫名其妙. 原来Javascript中 a.href 和 a.getAttrib ...

  4. JavaScript常用的方法和函数(setAttribute和getAttribute )

    仅记录学习的新知识和示例,无干货. 1.setAttribute和getAttribute          (Attribute:属性) setAttribute:为元素添加指定的属性,并为其赋值: ...

  5. [ javascript ] getElementsByClassName与className和getAttribute!

    对于javascript中的getElementsByClassName 在IE 6/7/8 不支持问题. 那么须要模拟出getElementsByClassName  须要採用className属性 ...

  6. javascript 中 dom.getAttribute("value") 与dom.value的差异

    dom 是一个 input type="text" 手动修改 input 的值, 使用 dom.getAttribute("value") 只能得到 html ...

  7. 读书笔记:JavaScript DOM 编程艺术(第二版)

    读完还是能学到很多的基础知识,这里记录下,方便回顾与及时查阅. 内容也有自己的一些补充. JavaScript DOM 编程艺术(第二版) 1.JavaScript简史 JavaScript由Nets ...

  8. jQuery学习之路(7)- 用原生JavaScript实现jQuery的某些简单功能

    ▓▓▓▓▓▓ 大致介绍 学习了妙味,用原生的JavaScript实现jQuery中的某些部分功能 定义自己的函数库lQuery ▓▓▓▓▓▓ $()选择器的实现 jQuery是面向对象的,所以自己编写 ...

  9. JavaScript特性(attribute)、属性(property)和样式(style)

    最近在研读一本巨著<JavaScript忍者秘籍>,里面有一篇文章提到了这3个概念. 书中的源码可以在此下载.我将源码放到了线上,如果不想下载,可以直接访问在线网址,修改页面名就能访问到相 ...

随机推荐

  1. tableView的cell显示不全的问题

    如果是最上面的cell没有显示完整 1.重新设置tableview的frame: 例如你的搜索框高度为50,那么设置self.tableview.frame= CGRectMake(0,50,self ...

  2. Spring属性编辑器详解

    1.常见的属性的注入:int,string,list,set,map 2.什么是属性编辑器及作用? (1)将spring配置文件中的字符串转换为相应的java对象 (2)spring内置了一些属性编辑 ...

  3. IOS简单的渐变绘制

    本文转载至 http://www.cnblogs.com/flychen/archive/2012/09/18/2690264.html 前几个星期项目中的音乐列表左边要添加阴影,做成平滑的效果.如图 ...

  4. IOS开发之----异常处理

    本文转载至 http://blog.csdn.net/chenyong05314/article/details/7906593 转载自:http://blog.sina.com.cn/s/blog_ ...

  5. LoadRunner hits per second 深入理解

    Hits per Second Graph The Hits per Second graph shows the number of HTTP requests made by Vusers to ...

  6. [URAL-1517][求两个字符串的最长公共子串]

    Freedom of Choice URAL - 1517 Background Before Albanian people could bear with the freedom of speec ...

  7. opencv使用记录

    /*2017-1-14*/ /*视频的读取...*/ int g_n=0; void on_change(int pos,void *)//看来void*不能省! { printf("g_n ...

  8. 百度小程序转换微信小程序

    Python脚本,一键转换Github地址:https://github.com/DWmelon/py-transfer-BdToWx 运行条件 具备Python环境,可在命令行中使用Python命令 ...

  9. JS dom最常用API

    //document方法:    var cont = document.getElementByIdx_x('cont'); //className给标签添加class    cont.classN ...

  10. SIFT算法详解(转)

    原文地址 http://blog.csdn.net/pi9nc/article/details/23302075 尺度不变特征变换匹配算法详解 Scale Invariant Feature Tran ...