【问题标题】:IE6 & 7, JavaScript "Member not found" bugIE6 和 7,JavaScript“未找到成员”错误
【发布时间】:2012-07-05 04:12:10
【问题描述】:

我编写了一些将图像嵌入页面的 JavaScript。

最终结果在所有浏览器(甚至 IE6 和 7)上都是成功的,但在 IE6 和 7 上我收到消息“第 15 行,第 5 个字符,未找到成员”。代码如下:

09: var url = getUrl();
10: url += 'Impression';
11: url += '?' + getParams();

12: var img = new Image();
13: img.src = url;
14: img.style = "display = 'none';";
15: document.body.insertBefore(img, document.body.firstChild);

IE6 或 7 是否不完全支持 document.body.insertBeforedocument.body.firstChild

【问题讨论】:

  • 为什么不使用document.body.appendChild(img)
  • 嗯,如果结果成功,你是怎么得到错误的?我的意思是,由于错误,它必须做一些不应该做的事情。
  • 是的,我附加的图像是 1x1 透明 gif,我试图将其设置为隐藏以作为额外的预防措施,但是将其设置为隐藏失败,但由于它已经是透明的,我无法没注意到!

标签: javascript css internet-explorer internet-explorer-7 internet-explorer-6


【解决方案1】:

IE 会因无效的 CSS 属性分配而引发错误。在这种情况下,img.style = "display = 'none';"; 无效。

应该是以下之一:

  • img.style.display = 'none';
  • img.style.cssText = "display:none;";

【讨论】:

    猜你喜欢
    • 2014-08-02
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    相关资源
    最近更新 更多