為什么我總是輸出undefined,我是谷歌瀏覽器。
?var mylist = document.getElementById("tcon");?
? ?var father = mylist.parentNode.parentNode.parentNode.lastChild.nodeVaule;
? ?document.write(father);
?var mylist = document.getElementById("tcon");?
? ?var father = mylist.parentNode.parentNode.parentNode.lastChild.nodeVaule;
? ?document.write(father);
2016-12-28
舉報(bào)
2016-12-28
mylist.parentNode.parentNode.parentNode.lastChild到這為止,指代的是一個(gè)元素節(jié)點(diǎn),元素節(jié)點(diǎn)的nodeValue不是null就是undefined.這一點(diǎn)你可以去看node的哪幾種類型以及它們的nodeValue。
如果想獲得元素里的文本內(nèi)容,你需要:
var father=mylist.parentNode.parentNode.parentNode.lastChild;
? ?document.write(father.innerHTML)