https://codepen.io/deepblue19...
Source code adopts the tag ,
traversing first.then store the acquired data in an "associative array",
(the text node of does key, and the value of an attribute title of does the value of the array)
I don"t understand why it is necessary to set up an array and then take values from the array. It is very existent to save first and then fetch it.
so I didn"t use the method in the book, just like this:
var abbr = document.getElementsByTagName("abbr");
if (abbr.length < 1) return false;
var dlist = document.createElement("dl");
for (var i = 0; i < abbr.length; iPP) {
var definition = abbr[i].getAttribute("title");
var text = abbr[i].innerText;
var dtitle = document.createElement("dt");
var dtitle_text = document.createTextNode(definition);
dtitle.appendChild(dtitle_text);
var ddesc = document.createElement("dd");
var ddesc_text = document.createTextNode(text);
ddesc.appendChild(ddesc_text);
dlist.appendChild(ddesc);
dlist.appendChild(dtitle);
}
document.body.appendChild(dlist);
with some IDE (HBuilder) built-in browser, it works, but neither chrome nor firefox can pass.
check for errors with Jslinter. Hint:
if (abbr.length < 1) return false;
>> index.js: "return" outside of function (2:23)
I am a rookie, and I don"t know how to do it, so I delete this item.
then, everything OK ~
WHY????