<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<!--公告的开始-->
<div class="affiche">
<div class="affiche_text left"><img src="images/gonggao_bg.jpg" width="18" height="19" /><samp style="float: left;">公告:</samp>
</div>
<!--第一段js-->
<script language="javascript">
<!--
// ------ 定义全局变量
var theNewsNum0;
var theAddNum0;
var totalNum0;
var CurrentPosion0=0;
var theCurrentNews0;
var theCurrentLength0;
var theNewsText0;
var theTargetLink0;
var theCharacterTimeout0;
var theNewsTimeout0;
var theBrowserVersion0;
var theWidgetOne0;
var theWidgetTwo0;
var theSpaceFiller0;
var theLeadString0;
var theNewsState0;
function startTicker()
{
// ------ 设置初始数值
theCharacterTimeout0 = 80;//字符间隔时间
theNewsTimeout0     = 5000;//新闻间隔时间
theWidgetOne0        =  "_";//新闻前面下标符1
theWidgetTwo0        =  "-";//新闻前面下标符
theNewsState0       = 1;
//theNewsNum0        = document.body.children.incoming.children.NewsNum.innerText;//新闻总条数
//add by lin
theNewsNum0        = document.getElementById("incoming").children.AllNews.children.length;//新闻总条数
theAddNum0        = document.getElementById("incoming").children.AddNews.children.length;//补充条数
totalNum0   =theNewsNum0+theAddNum0;
theCurrentNews0     = 0;
theCurrentLength0    = 0;
theLeadString0       = " ";
theSpaceFiller0      = " ";
runTheTicker();
}
// --- 基础函数
function runTheTicker()
{
if(theNewsState0 == 1)
{
if(CurrentPosion0<theNewsNum0){
setupNextNews();
}
else{
setupAddNews();
}
CurrentPosion0++;
if(CurrentPosion0>=totalNum0||CurrentPosion0>=5) CurrentPosion0=0;  //最多条数不超过5条
}
if(theCurrentLength0 != theNewsText0.length)
{
drawNews();
}
else
{
closeOutNews();
}
}
// --- 跳转下一条新闻
function setupNextNews()
{
theNewsState0 = 0;
theCurrentNews0 = theCurrentNews0 % theNewsNum0;
theNewsText0 = document.getElementById("AllNews").children[theCurrentNews0].children.Summary.innerText;
theTargetLink0 = document.getElementById("AllNews").children[theCurrentNews0].children.NewsLink.innerText;
theCurrentLength0 = 0;
document.all.hottext.href = theTargetLink0;
theCurrentNews0++;
}
function setupAddNews()
{
theNewsState0 = 0;
theCurrentNews0 = theCurrentNews0 % theAddNum0;
theNewsText0 = document.getElementById("incoming").children.AddNews.children[theCurrentNews0].children.Summary.innerText;
theTargetLink0 = document.getElementById("incoming").children.AddNews.children[theCurrentNews0].children.NewsLink.innerText;
theCurrentLength0 = 0;
document.all.hottext.href = theTargetLink0;
theCurrentNews0++;
}
// --- 滚动新闻
function drawNews()
{
var myWidget;
if((theCurrentLength0 % 2) == 1)
{
myWidget = theWidgetOne0;
}
else
{
myWidget = theWidgetTwo0;
}
document.all.hottext.innerHTML = theLeadString0 + theNewsText0.substring(0,theCurrentLength0) + myWidget + theSpaceFiller0;
theCurrentLength0++;
setTimeout("runTheTicker()", theCharacterTimeout0);
}
// --- 结束新闻循环
function closeOutNews()
{
document.all.hottext.innerHTML = theLeadString0 + theNewsText0 + theSpaceFiller0;
theNewsState0 = 1;
setTimeout("runTheTicker()", theNewsTimeout0);
}
window.onload=startTicker;
//-->
</script>
<!--公告栏 start-->
        <div id="visible"><a href="" id="hottext" target="_blank" style="color:#686868;"></a></div>
        <div id="incoming" style="DISPLAY: none">
            <div id="AllNews">
                <ul id="1">
                <li id="Summary">111111111111111111111111111111111111111111111111</li>
                <li id="NewsLink">11111</li>
                </ul>
                <ul id="2">
                <li id="Summary">222222222222222222222222222222222222222222222222</li>
                <li id="NewsLink">22222</li>
                </ul>
            </div>        <div id="AddNews"></div>
        </div>
</div>
<!--公告栏 end--><!--第二段js-->
<script language="javascript" >
document.writeln("<div class=\"caidan\" id=luoye onmouseover=Show() onmouseout=Shrink()>");
document.writeln(" <div class=\"caidan-t\">");
document.writeln(" <a target=\"_blank\" class=\"zhongxin\" style=\"cursor: pointer\" onclick=\"javascript:window.open('', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no');\" alt=\"咨询\">咨询</a>");
document.writeln(" <a target=\"_blank\" class=\"kefu\" style=\"cursor: pointer\" onclick=\"javascript:window.open('', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no');\" alt=\"咨询\">咨询</a>");
document.writeln(" <a href=\"\" target=\"_blank\" class=\"baoming\">咨询</a></div>");
document.writeln(" <div class=\"button\"></div>");
document.writeln("</div>"); kb96=function (id,_top,_right){
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.right=_right+"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 (){
kb96('luoye',120,-180)
}
var lastScrollY=0; 
var InterTime = 1;
var maxWidth=-1;
var minWidth=-180;
var numInter = 20;
var BigInter;
var SmallInter
var o =  document.getElementById("luoye");
var i = parseInt(o.style.right);
function Big()
{
if(parseInt(o.style.right)<maxWidth)
{
i = parseInt(o.style.right);
i += numInter;
o.style.right=i+"px";
if(i==maxWidth)
clearInterval(BigInter);
}
}
function Show()
{
clearInterval(SmallInter);
clearInterval(BigInter);
BigInter = setInterval(Big,InterTime);
}
function Small()
{
if(parseInt(o.style.right)>minWidth)
{
i = parseInt(o.style.right);
i -= numInter;
o.style.right=i+"px";

if(i==minWidth)
clearInterval(SmallInter);
}
}
function Shrink()
{
clearInterval(SmallInter);
clearInterval(BigInter);
SmallInter = setInterval(Small,InterTime);
}</script>
</body>
</html>

解决方案 »

  1.   

    声明了太多的全局变量,决不是JS代码设计的最佳实践。
    假设你在此页面有变量a、b、c、d,对象person、color,方法func1、func2,就应该把它们收编到同一个对象下,就好像“命名空间”一样,来最大减轻对全局变量的污染和对其他代码的影响。var mySpace = {
        var theNewsNum0;
        var theAddNum0;
        var totalNum0;
        //...
        function startTicker() {
            //...
        }    function runTheTicker() {
            //...
        }...
    };下面使用另一个形如mySpace2这样的“空间”,完事了
      

  2.   

    <script>
    function config(){
    this.theNewsNum0 = null;
        this.theAddNum0 = null;
    }var s = new config;
    var m = new config;s.theNewsNum0 = 1;
    m.theNewsNum0 = 2;alert("s: " + s.theNewsNum0 + ", m:" + m.theNewsNum0);
    </script>结果:s: 1, m: 2;说明互不影响。 因此,在你的文件中,可以将全局变量变为: config. 然后在“// ------ 设置初始数值”时,分别赋值。相互间使用相同结构,但不同参数的config,将相互不影响。