JS DOM:显示文献来源链接表
2016-05-26 20:56
369 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Explaining the Ddocument Ob Model</title> <link href="style08.css" type="text/css" rel="stylesheet" /> </head> <body> <h1> What is the Document object Model?</h1> <p> The <abbr title="Worle Wide Web Consortium">W3C</abbr> defines the <abbr title="Object Model">DOM</abbr> as: </p> <blockquote cite="http://www.w3.org/DOM/"> <P> A platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content,structure and styles of documents. </p> </blockquote> <p> It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate <abbr title="eXtensible Markup Language">XML</abbr> documents. </p> <script src="8.5.js"></script> </body> </html>
function addLoadEvent(func){ //不管在页面加载完毕执行多少个函数,都应付自如 var oldonload = window.onload; if(typeof window.onload != 'function'){ window.onload = func; }else{ window.onload = function(){ oldonload(); func(); } } } function displayCitations(){ //检查兼容性 if(!document.getElementsByTagName||!document.createElement||!document.createTextNode) return false; var quotes = document.getElementsByTagName("blockquote"); for( var i = 0;i < quotes.length; i++){ if(!quotes[i].getAttribute("cite")) continue; var url = quotes[i].getAttribute("cite"); //获取cite属性的值:也就是链接 var quoteChildern = quotes[i].getElementsByTagName("*"); //因为p节点和blockquote节点之间有个换行符,不少浏览器会把它解释为几个文本节点,这样一来,blockquote元素节点的lastChild属性 //检查长度是否小于1 ,如果是,立刻退出本次循环。 //就是一个文本节点不是p元素节点。该条语句是为了获取最后一个元素节点的位置。建议:如果没有百分之百把握,一定要去检查 if(quoteChildern.length < 1) continue; //lastChild的nodeType属性,以免获取节点错误。 var elem = quoteChildern[quoteChildern.length - 1]; var link = document.createElement("a"); //创建a元素 var link_text = document.createTextNode("source"); link.appendChild(link_text); link.setAttribute("href", url); //把href属性添加给新链接 //插入链接 var superscript = document.createElement("sup"); //sup元素:指定内含文本要以上标的形式显示,通常比当前字体稍小。 superscript.appendChild(link); //以上语句html文本:<sup><a href="http://www.w3.org/DOM/">source</a></sup> elem.appendChild(superscript); //追加为变量elem的最后一个子节点 } } addLoadEvent(displayCitations);
浏览器效果:
相关文章推荐
- C#使用LitJson对Json数据解析
- 【转】js 关键字 in 的使用方法
- 用JS生成MIDI文件(附代码)
- 原生 JavaScript 图片裁剪效果
- 解决jsCookie 页面跳转失效问题
- [JSOI2016]反质数序列
- 2016年5月26日晚上(妙味课堂js基础-2笔记四(BOM))
- 2016年5月26日晚上(妙味课堂js基础-2笔记三(DOM))
- 实习入职第六天---快速查看JSON格式化工具
- 便签4-js数组
- Extjs框架html5中input、textarea的placeholder,元素内容为空时,颜色为灰色
- JSON.parse解析json数据及取值的几种方式
- 玩转js--炫酷抽奖轮盘
- js 去掉字符串前后空格
- IntelliJ IDEA中js代码报如下警告的解决方法
- high performence javascript(高性能JavaScript)
- 在JSP中添加图片
- [RxJS] Combination operator: withLatestFrom
- JSP和Servlet之间跳转总结
- js模版引擎介绍