魔鬼glen 2015-08-14 15:15 采纳率: 70%
浏览 1346
已采纳

请问代码在两种环境下执行不一样啊?

原意是在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;
}

还望解答,至诚感谢。

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-08-14 15:23
    关注

    典型的js hack
    IE的getAttribute有bug

    http://blog.csdn.net/zxsrendong/article/details/6650516

    whichpic.getAttribute("title")
    这里判断下避免返回null

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序