·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设问答 >> 解决javascript不兼容除IE外其他浏览器问题

解决javascript不兼容除IE外其他浏览器问题

作者:佚名      网站建设问答编辑:admin      更新时间:2022-07-23

今天,老大要我处理一个网站的兼容问题,一般兼容性问题是兼容其他浏览器,就IE不兼容,而这个有点特殊,只兼容IE,不兼容其他浏览器。初步观察以后,我发现是Javacript的问题。而不关div和css什么事情。

这是原来的代码:

<SCRIPT language=JavaScript>
marqueesHeight=550;
stopscroll=false;

with(flash){
style.width=235;
style.height=marqueesHeight;
style.overflowX=”visible”;
style.overflowY=”hidden”;
noWrap=true;
onmouseover=new Function(“stopscroll=true”);
onmouseout=new Function(“stopscroll=false”);
}
document.write(‘<div id=”templayer1″ style=”position:absolute;z-index:1;visibility:hidden;top:6px;”></div>’);

preTop=0; currentTop=0;

function init1(){
templayer1.innerHTML=”";
while(templayer1.offsetHeight<marqueesHeight){
templayer1.innerHTML+=flash.innerHTML;
}
flash.innerHTML=templayer1.innerHTML+templayer1.innerHTML;
setInterval(“scrollUp1()”,20);//?
}
document.body.onload=init1;

function scrollUp1(){
if(stopscroll==true) return;
preTop=flash.scrollTop;
flash.scrollTop+=1;
if(preTop==flash.scrollTop){
flash.scrollTop=templayer1.offsetHeight-marqueesHeight;
flash.scrollTop+=1;
}
}
</SCRIPT>

这其实就是很普通的轮播。而造成不兼容的问题就是因为代码写的不完善,下面我给出我的解决方案:

<SCRIPT language=JavaScript>
marqueesHeight=550;
stopscroll=false;
var marquees=document.getElementById(“flash”);
var templayer=document.getElementById(“templayer1″);
with(flash){
flash.style.width=235+”px”;
flash.style.height=marqueesHeight+”px”;
flash.style.overflowX=”visible”;
flash.style.overflowY=”hidden”;
flash.noWrap=true;
flash.onmouseover=new Function(“stopscroll=true”);
flash.onmouseout=new Function(“stopscroll=false”);
}
document.write(‘<div id=”templayer1″ style=”position:absolute;z-index:1;visibility:hidden;top:6px;”></div>’);
var preTop=0; currentTop=0;
function init1(){
templayer1.innerHTML=”";
while(templayer1.offsetHeight<marqueesHeight){
templayer1.innerHTML+=flash.innerHTML;
}
flash.innerHTML=templayer1.innerHTML+templayer1.innerHTML;
setInterval(“scrollUp1()”,10);//?
}
window.onload=init1;
function scrollUp1(){
if(stopscroll==true) return;
preTop=flash.scrollTop;
flash.scrollTop+=1;
if(preTop==flash.scrollTop){
flash.scrollTop=templayer1.offsetHeight-marqueesHeight;
flash.scrollTop+=1;
}
}
</SCRIPT>

将代码写完善,不仅仅会更兼容,也会更好看,我们写程序,千万不要贪图一时的快速,我们要写出好程序,千万不能出现如上的问题。

除非注明,胡小易博客文章均为原创,转载请以链接形式标明本文地址

本文地址:http://huxiaoyi.com/website/20120706.html