繁体   English   中英

Internet Explorer 7 Javascript问题?

[英]Internet Explorer 7 Javascript Problem?

该脚本可在IE8和Firefox中使用,但不会在IE7中应用“当前”类或清除“样式”。 有人知道为什么吗? 为了安全起见,在此处将真实ID和文件路径替换为通用ID和文件路径。

var img = document.getElementById("imageID");
var div = document.getElementById("divID");

if (img.getAttribute('src') == "imagefilepath.gif") {
div.className = "current";
div.setAttribute('style', ' ' );
}

看来IE7在src属性中包含了整个路径,但您的条件没有得到满足。

http://jsfiddle.net/4E58r/1/

您可以使用此功能在所有版本中都可以使用:

someId.setAttribute("className", "someClassName") || 
someId.setAttribute("class", "someClassName")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM