[問題] IE fail
各位好,JS新手上路..遇到了一點問題..
在下想在樂多的banner說明欄內上使用外連js加入一單純的導覽選單
banner區塊的配置大致如下
┌div #banner ────────┐
│┌h1.blogtitle──────┐│
││標題 ││
│└────────────┘│
│┌div .description────┐│
││<外連script></script> ││
│└────────────┘│
└──────────────┘
我想令該部分變成
┌div #banner ────────┐
│┌h1.blogtitle──────┐│
││標題 ││
│└────────────┘│
│┌div .description────┐│
││<ul id="mainmenu"> ││
││ <li>連結</li> ││
││ <li>連結</li> ││
││</ul> ││
│└────────────┘│
└──────────────┘
會使用外連js是擔心說明欄字數限制的問題
以下是我使用的外連選單內容
外連js部分
--------------------------------------
function addMainmenu()
{
var menuUl = document.createElement("ul");
menuContent = new Array(2)
menuContent[0] = "連結文字1";
menuContent[1] = "連結文字2";
menuUrl = new Array(2)
menuUrl[0] = "http://xxx";
menuUrl[1] = "http://ooo";
if (document.getElementById)
{
for (i=0;i<menuContent.length;i++)
{
var text = document.createTextNode(menuContent[i]);
var alink = document.createElement("a");
var menuLi = document.createElement("li");
alink.appendChild(text);
alink.href = menuUrl[i];
menuLi.appendChild(alink);
menuUl.appendChild(menuLi);
}
var bannerDIV = document.getElementById("banner");
bannerDIV.appendChild(menuUl);
menuUl.id = "mainmenu";
}else {
document.write("<" + "ul id=\"mainmenu\"" + ">");
for (i=0;i<menuContent.length;i++){
document.write("<" + "li" + ">");
document.write("<" + "a href=\"" + menuUrl[i] + "\">");
document.write( menuContent[i] + "<" + "/a" + ">");
document.write("<" + "/li" + ">");
}
document.write("<" + "/ul" + ">")
}
}
addMainmenu();
------------------------------------
這部分在Fx上面跑是沒有問題的,但萬萬沒想到一換成IE瀏覽,讀取到description
欄位後,就顯示IE發生錯誤視窗,之後就自動切到找不到網頁的畫面。
原先製作了一個僅含 DIV #banner 的網頁測試,在兩瀏覽器下都是沒有問題的,
不知道到底是發生了什麼問題讓IE產生這麼嚴重的錯誤,還是發生了JS衝突?畢竟
這blog上並沒有使用多少js的部分?還是發生了我疏忽的撰寫方式..呃
原始的頁面在 http://blog.roodo.com/3forks
而外連的js在 http://3forksfilm.googlepages.com/3forks.js
出問題的部分已經先用註解讓停止運作了
希望有人能夠幫忙解答..不好意思..
註: ul #mainmenu 先使用css隱藏了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.126.19.41
※ 編輯: HiroshiKen 來自: 122.126.19.41 (01/04 23:21)
→
01/05 00:08, , 1F
01/05 00:08, 1F
→
01/05 00:24, , 2F
01/05 00:24, 2F
→
01/05 00:24, , 3F
01/05 00:24, 3F
→
01/05 00:25, , 4F
01/05 00:25, 4F