原意是在DW中圖片可以在頁面中切換,而在chrome中就變成直接跳轉到圖片了,頁面就不存在了。
關鍵代碼如下:
function showPic(whichpic) {
var source = whichpic.getAttribute("href");
var placeholder = document.getElementById("placeholder");
var text = whichpic.getAttribute("title");
var description = document.getElementById("description");
placeholder.setAttribute("src",source);
description.firstChild.nodeValue = text;
}
而多添加了些判斷就能解決這問題,這是我不理解的地方。
代碼如下
function showPic(whichpic) {
var source = whichpic.getAttribute("href");
var placeholder = document.getElementById("placeholder");
placeholder.setAttribute("src",source);
if (whichpic.getAttribute("title")) {
var text = whichpic.getAttribute("title");
} else {
var text = "";
}
var description = document.getElementById("description");
if (description.firstChild.nodeType == 3) {
description.firstChild.nodeValue = text;
}
return false;
}
還望解答,至誠感謝。
典型的js hack
IE的getAttribute有bug
http://blog.csdn.net/zxsrendong/article/details/6650516
whichpic.getAttribute("title")
這裡判斷下避免返回null