我有一个灯箱类型模式窗口无法正常使用IE的问题。我已经发现问题是由于隐藏图像的style属性为'display:none'。这在所有其他浏览器中都可以正常工作。但对于IE浏览器,我需要将onload值更改为'display:block',然后直接返回到'display:none'来解决问题。如何更改HTML元素样式,然后使用JS恢复onLoad()?
任何人都可以告诉我如何做到这一点?我需要将这个规则应用到类“图像”的多个div。
我有一个灯箱类型模式窗口无法正常使用IE的问题。我已经发现问题是由于隐藏图像的style属性为'display:none'。这在所有其他浏览器中都可以正常工作。但对于IE浏览器,我需要将onload值更改为'display:block',然后直接返回到'display:none'来解决问题。如何更改HTML元素样式,然后使用JS恢复onLoad()?
任何人都可以告诉我如何做到这一点?我需要将这个规则应用到类“图像”的多个div。
在你的CSS
.image{ display:none; }
在HTML
...
<body onload="switch" >
...
<script type="text/javascript">
function switch(){
var divs = document.getElementsByClassName("image"); // not supported by all browsers but you can easily find implementations on the web
for(var index=0;index<divs.length;index++)
{
divs[index].style.display='block';
}
}
</script>
</body>
jQuery的版本:
$(document).ready(function(){
$(".image").show();
});
你是否在使用任何框架?我问,因为这可以改变您放置以下代码的位置。
我还不能肯定,如果这个工程在IE浏览器,但它可以:
<img ... onload="this.style.display='block';this.style.display='none';">
做不到这一点把它放在你的身体/文件的onLoad功能(如果你没有一个创建一个)。
function docOnLoad()
{
...
document.getElementById('img_in_question').style.display = 'block';
document.getElementById('img_in_question').style.display = 'none';
...
}
编辑:修复我的horribad拼写。
谢谢。我应该提到我正在使用jQuery。我现在就试试这个 – igniteflow 2010-06-04 14:21:42