下面是这个代码,确实是命名冲突了         var _delta=0.15
var _collection;
function _floaters() {
this.items = [];
this.addItem = function(id,x,y,content)
  {
document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');

var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y; this.items[this.items.length] = newItem;
  }
this._play = function()
  {
_collection = this.items
setInterval('_play()',10);
  }
}
function _play()
{ for(var i=0;i<_collection.length;i++)
{
var followObj = _collection[i].object;
var followObj_x = (typeof(_collection[i].x)=='string'?eval(_collection[i].x):_collection[i].x);
var followObj_y = (typeof(_collection[i].y)=='string'?eval(_collection[i].y):_collection[i].y); if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*_delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
} if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*_delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
followObj.style.display = '';
}
}

var _theFloaters = new _floaters();
_theFloaters.addItem('followDiv1','document.body.clientWidth-105',5,'<br><br><embed src="js/shengming.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="70" height="200"></embed><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a href=shichang/xuazehezuo.htm target=_blank><img src=js/xuanze.gif border=0></a>');
_theFloaters.addItem('followDiv2',5,5,'                              <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a href=shichang/touzixuanxiang.htm target=_blank><img src=js/liuji.gif border=0></a>');
_theFloaters._play();上面的代码是我改过以后的
不过有点不太明白,<script src="">是不是就是把那个JS文件的内容插入到
<script></script>之间如果我有两个JS文件
1.js中定义了变量var v;function f();
2.js中也定义了变量var v;function f();
 
在同一个页面中加入<script src="1.js"/>
<script src="2.js"/>是不是也就有冲突了

解决方案 »

  1.   

    试验了一下
    :
    <script language="javascript">
    <!--
    var n=10;
    var n=20;
    function f1()
    {
     alert("f1");
    }
    function f1()
    {
      alert("f2");
    }-->
    <body onload="javasript:window.alert(n)>
    <p onlick="f1()">
    好像后定义的覆盖先前定义的
    由于n在函数外面是全局的;
      

  2.   

    这明显就是往网页里插广告嘛,BS啊BS~~
      

  3.   

    呵呵,楼上的,又不是只有广告才这么写,程序里面当然也需要的啊,看用在什么方面而已;
    to:jobs002(赏花赏月赏春光,The More you know,The More you forget.....) 这么看来,每一个<script></script>之间的变量,函数名都不能一样了
    要不就冲突了
    而且一个<script></script>中定一个全局变量,那他在整个页面里面就是全局变量了
    不知道理解的对不?
      

  4.   

    http://bbs.51js.com/viewthread.php?tid=21139&fpage=1
    可能对你有用处,还没有仔细看.........
      

  5.   

    在函数外面定义的变量为:全局的
    var m1;//全局的,只限本叶面;
    function test()