<! Doctype html>Function addloadevent (func) { //does not matter how many functions are executed after the page is loaded var oldonload = window.onload;if (typeof window.onload != ' function ') {window.onload = func;} Else{window.onload = function () {oldonload (); func ();}}} Function displaycitations () {//Check compatibility 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"); //gets the value of the cite property: that is, the link var quotechildern = quotes[i].getelementsbytagname ("*"); //because there is a line break between the P node and the BLOCKQUOTE node, Many browsers will interpret it as several text nodes, so that the LastChild attribute of the BLOCKQUOTE element node//Check whether the length is less than 1 , and if so, exit this loop immediately. //is a text node that is not a P element node. The statement is to get the position of the last element node. Recommendation: If not absolutely sure, be sure to check if (quotechildern.length < 1) continue; //lastchild the NodeType property to avoid getting node errors. var elem = quotechildern[quotechildern.length - 1]; var link = document.createelement ("a"); //Create a element Var link_text = document.createtextnode ("source"); Link.appendchild (Link_text); Link.setattribute ("href", url); // Add the href attribute to the new link//Insert link var superscript = document.createelement ("Sup"); //sup element: Specifies that the included text is displayed in the form above, usually slightly smaller than the current font. Superscript.appendchild (link); //above statement HTML text: <sup><a href= " http://www.w3.org/DOM/">source</a></sup>elem.appendchild (superscript); //is appended to the last child node of the variable Elem} }addloadevent (displaycitations);
Browser effects:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/81/FF/wKioL1dG893xNu75AAAzYOZYmW4003.png-wh_500x0-wm_3 -wmp_4-s_4134423147.png "title=" Qq20160526205722.png "alt=" Wkiol1dg893xnu75aaazyozymw4003.png-wh_50 "/>
JS DOM: Show Source Link table