最近需要在项目中的页面右下角做一个右下角弹出的例子,于是就在网上找到了AlertBox的小组件很不错,于是就拿来用。但是遇到了问题。在IE7下正常使用,但是就是在IE6下一直报脚本错误。
难道是IE6不支持?
但是下载的例子在IE6下可以弹出呀。就是把它改成jsp就报“AlertBox未定义”。最后经理告诉我,html既然能跑起来jsp就没问题。
最后发现是页面的字符集不一致的原因,特写出来给那些也喜欢这个组件但是还未这个问题郁闷的朋友们!
我改造过的能够定时弹出和关闭的一段代码:
<script type="text/javascript" language="javascript">
(function(){
var timer, target, current,
ab = new AlertBox("idBox2", {fixed: true,onShow: function(){
clearTimeout(timer); this.box.style.bottom = this.box.style.right = 0;},
onClose: function(){ clearTimeout(timer); }});
function hide(){
ab.box.style.bottom = --current + "px";
if( current <= target ){
ab.close();
} else {
timer = setTimeout( hide, 10 );
}
}
$$("idBoxClose2").onclick = function(){
target = -ab.box.offsetHeight; current = 0; hide();
}
$$("idBoxOpen2").onclick = function(){ ab.show(); }
setTimeout("document.getElementById('idBoxOpen2').click();",5000);
setTimeout("document.getElementById('idBoxClose2').click();",15000);
})()
</script>
献丑了。
本文介绍了一个在IE6中遇到的AlertBox组件兼容性问题,并分享了一段经过改造的定时弹出和关闭的示例代码。
286

被折叠的 条评论
为什么被折叠?



