两段js代码有冲突,求高手帮忙看看 js 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大哥你就不能把JS代码放到HTML 代码框里吗??? 那么乱谁看啊 第一段:<script language="javascript" type="text/javascript">var s,s2,s3,s4,timer;function init(){s=getid("div1");s2=getid("div2");s3=getid("div3");s4=getid("scroll");s4.style.width=(s2.offsetWidth*3)+"px";s3.innerHTML=s2.innerHTML;timer=setInterval(mar,30)}function mar(){if(s2.offsetWidth<=s.scrollLeft){s.scrollLeft-=s2.offsetWidth;}else{s.scrollLeft++;}}function getid(id){return document.getElementById(id);}window.onload=init;</script>第二段:<SCRIPT language=javascript>客服果果=function (id,_top,_left){var me=id.charAt?document.getElementById(id):id, d1=document.body, d2=document.documentElement;d1.style.height=d2.style.height='100%';me.style.top=_top?_top+'px':0;me.style.left=_left+"px";//[(_left>0?'left':'left')]=_left?Math.abs(_left)+'px':0;me.style.position='absolute';setInterval(function (){me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px';},10+parseInt(Math.random()*20));return arguments.callee;};window.onload=function (){客服果果('xixi',100,-152)}</SCRIPT><SCRIPT language=javascript> lastScrollY=0; var InterTime = 1;var maxWidth=-1;var minWidth=-152;var numInter = 8;var BigInter ;var SmallInter ;var o = document.getElementById("xixi");var i = parseInt(o.style.left);function Big(){if(parseInt(o.style.left)<maxWidth){i = parseInt(o.style.left);i += numInter; o.style.left=i+"px"; if(i==maxWidth)clearInterval(BigInter);}}function toBig(){clearInterval(SmallInter);clearInterval(BigInter);BigInter = setInterval(Big,InterTime);}function Small(){if(parseInt(o.style.left)>minWidth){i = parseInt(o.style.left);i -= numInter;o.style.left=i+"px";if(i==minWidth)clearInterval(SmallInter);}}function toSmall(){clearInterval(SmallInter);clearInterval(BigInter);SmallInter = setInterval(Small,InterTime);}</SCRIPT> 且不看楼主你找的这两段代码是实现什么功能,单从描述中谁放到下面谁就执行来看,八成由于出现了两次window.onload = function(){} ,就好比在同一个脚本中定义了相同名称的函数(或者多个且彼此之间参数不同),js引擎只会执行最后一次定义的那个函数。楼主可以把两个方法合并或者采用jquery的load写法,$(function(){}) 请教客户端js和服务器端js的区别 jqury Ajax Error错误如何解决 extjs后台数据库中记录内容更改,如何刷新前台store上对应记录 大侠过来看看小弟的问题 让层居中(定义DOCTYPE 的WEB页) 运行时会自动关闭IE 高手救急!在先等,谢谢...... 请教关于 document.write()的问题,谢谢各位大哥 javascript问题 80分各位大虾小弟急需谢谢 快快快!!!!!!!!! 模拟鼠标键盘? 循环太多,导致脚本崩溃,寻求解决方法 谁会js控制div中的内容可通过左右键按钮滚动,急用!!!11
<script language="javascript" type="text/javascript">
var s,s2,s3,s4,timer;
function init(){
s=getid("div1");
s2=getid("div2");
s3=getid("div3");
s4=getid("scroll");
s4.style.width=(s2.offsetWidth*3)+"px";
s3.innerHTML=s2.innerHTML;
timer=setInterval(mar,30)
}
function mar(){
if(s2.offsetWidth<=s.scrollLeft){
s.scrollLeft-=s2.offsetWidth;
}else{s.scrollLeft++;}
}
function getid(id){
return document.getElementById(id);
}
window.onload=init;
</script>第二段:
<SCRIPT language=javascript>
客服果果=function (id,_top,_left){
var me=id.charAt?document.getElementById(id):id, d1=document.body, d2=document.documentElement;
d1.style.height=d2.style.height='100%';me.style.top=_top?_top+'px':0;me.style.left=_left+"px";//[(_left>0?'left':'left')]=_left?Math.abs(_left)+'px':0;
me.style.position='absolute';
setInterval(function (){me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px';},10+parseInt(Math.random()*20));
return arguments.callee;
};
window.onload=function (){
客服果果
('xixi',100,-152)
}
</SCRIPT><SCRIPT language=javascript>
lastScrollY=0; var InterTime = 1;
var maxWidth=-1;
var minWidth=-152;
var numInter = 8;var BigInter ;
var SmallInter ;var o = document.getElementById("xixi");
var i = parseInt(o.style.left);
function Big()
{
if(parseInt(o.style.left)<maxWidth)
{
i = parseInt(o.style.left);
i += numInter;
o.style.left=i+"px";
if(i==maxWidth)
clearInterval(BigInter);
}
}
function toBig()
{
clearInterval(SmallInter);
clearInterval(BigInter);
BigInter = setInterval(Big,InterTime);
}
function Small()
{
if(parseInt(o.style.left)>minWidth)
{
i = parseInt(o.style.left);
i -= numInter;
o.style.left=i+"px";if(i==minWidth)
clearInterval(SmallInter);
}
}
function toSmall()
{
clearInterval(SmallInter);
clearInterval(BigInter);
SmallInter = setInterval(Small,InterTime);}</SCRIPT>