我這個腳本的工作,以產生一個目錄表:的createElement與createElementWithClass
https://github.com/nanotube/generated_toc
我使用它這個測試頁面上。正如你所看到的,所創建的[返回]鏈接實在是太醜:
http://www.utahrails.net/up/up-loco-features_toc-test.php
應用CSS樣式是創造需求「[返回頁首]」鏈接,在div上課。
這工作:
// create a "back to top" link
if (back_to_top == 'on'){
newdiv = document.createElement('div');
newdiv.innerHTML = "<a href='#beforetoc'>[back to top]</a>";
this_head_el.parentNode.insertBefore(newdiv, this_head_el.nextSibling);
但這並不。在TOC中的內容消失,所有的鏈接消失:
// create a "back to top" link
if (back_to_top == 'on'){
newdiv = document.createElementWithClass('div', 'back-to-top');
newdiv.innerHTML = "<a href='#beforetoc'>[back to top]</a>";
this_head_el.parentNode.insertBefore(newdiv, this_head_el.nextSibling);
我真的很新的腳本,我不能看到問題的所在。
爲什麼你認爲有一個名爲'createElementWithClass()'方法? – jfriend00 2013-02-25 16:42:57
JavaScript控制檯顯示什麼? – 2013-02-25 16:43:13
@jfriend:謝謝你確認它不存在。我很驚訝,直到現在我才錯過了這樣一個有用的功能/方法。 – 2013-02-25 16:43:59