displaycitations.js

来自「《JavaScript DOM编程艺术》一书中的配套源代码」· JavaScript 代码 · 共 28 行

JS
28
字号
function displayCitations() {  if (!document.getElementsByTagName || !document.createElement || !document.createTextNode) return false;// get all the blockquotes  var quotes = document.getElementsByTagName("blockquote");// loop through all the blockquotes  for (var i=0; i<quotes.length; i++) {// if there is no cite attribute, continue the loop    if (!quotes[i].hasAttribute("cite")) continue;// store the cite attribute    var url = quotes[i].getAttribute("cite");// get all the element nodes in the blockquote    var quoteChildren = quotes[i].getElementsByTagName('*');// if there are no element nodes, continue the loop    if (quoteChildren.length < 1) continue;// get the last element node in the blockquote    var elem = quoteChildren[quoteChildren.length - 1];// create the markup    var link = document.createElement("a");    var link_text = document.createTextNode("source");    link.appendChild(link_text);    link.setAttribute("href",url);    var superscript = document.createElement("sup");    superscript.appendChild(link);// add the markup to the last element node in the blockquote    elem.appendChild(superscript);  }}addLoadEvent(displayCitations);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?