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. Spring cloud微服务实战——基于OAUTH2.0统一认证授权的微服务基础架构

    https://blog.csdn.net/w1054993544/article/details/78932614

  2. Python学习总结之四 -- 这就是Python的字典

    字典原来是这么回事儿 Python学习到现在,我们已经知道,如果想将值分组到结构中,并且通过编号对其进行引用,列表就可以派上用场.不过,今天,我们将学到一种通过名字引用值的数据结构,应该知道这种数据类 ...

  3. strpos与strstr之间的区别

    string strstr(string haystack,string needle) 返回haystack中从第一 个needle开头到haystack末尾的字符串. 如果未找到needle 返回 ...

  4. iOS项目 -- 模仿花椒直播做的第二层界面完整版

    ,项目开始做了,好遗憾的是,花椒app有更新了版本,

  5. 九度OJ 1032:ZOJ (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4569 解决:2561 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的 ...

  6. 连通性 保证f具有介值性质

  7. centos开放80端口

    增加一条规则 #/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 将更改进行保存 /etc/rc.d/init.d/iptables save 查 ...

  8. 一个商品SKU是怎么生成的

    首先说一说什么是SKU.......自己百度去... 类似京东上面,未来人类S5这个台笔记本(没错,我刚入手了) 都是S5这个型号,但是因为CPU,显卡,内存,硬盘等不同,价格也不一样.CPU,显卡, ...

  9. CSS3 3D下拉折叠菜单

    在线演示 本地下载

  10. linux字符设备学习笔记【原创】

    1.申请设备号 int register_chrdev_region(dev_t from, unsigned count, const char *name) 指定从设备号from开始,申请coun ...