您的位置:首页 > Web前端 > JavaScript

JS DOM编程艺术——显示文献来源链接表—— JS学习笔记2015-7-17(第86天)

2015-07-17 22:39 761 查看
function displayCitations(){
// 取得所有引用
var quotes = document.getElementsByTagName("blockquote");
//遍历引用
for( var i=0; i<quotes.length; i++){

// 如果没有cite属性,继续循环
if(!quotes[i].getAttribute("cite")) continue;
// 保存cite属性
var url = quotes[i].getAttribute("cite");
// 取得引用中所有的元素节点
var quoteChildren = quotes[i].getElementsByTagName("*");
// 如果没有元素节点,继续循环
if( quoteChildren.length < 1) continue;
// 取得引用中的最后一个元素节点
var elem = quoteChildren[quoteChildren.length-1];
// 创建标记
var link = document.createElement("a");
var link_text = document.createTextNode("source");
link.appendChild(link_text);
var superscript = document.createElement("sup");
superscript.appendChild(link);
// 把标记添加到引用中的最后一个元素节点;
elem.appendChild(superscript);
}

}

addLoadEvent(displayCitations);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: