错得不是一两处。varId = window.setInterval("moveAd()",moveSpeed);  //启动飘浮
-->>>
varId = window.setInterval("move_ad()",moveSpeed);  //启动飘浮
var ad_Left_Top=parseInt(document.getElementById('float_left').style.top);
var ad_Right_Top=parseInt(document.getElementById('float_right').style.top);
var ad_LHeight=parseInt(document.getElementById('float_left').style.Height);
var ad_RHeight=parseInt(document.getElementById('float_right').style.Height); 
-->>>
var ad_Left_Top=parseInt(document.getElementById('float_left').offsetTop);
var ad_Right_Top=parseInt(document.getElementById('float_right').offsetTop);
var ad_LHeight=parseInt(document.getElementById('float_left').clientHeight);
var ad_RHeight=parseInt(document.getElementById('float_right').clientHeight);编程风格太乱,多锻炼锻炼吧。

解决方案 »

  1.   

    document.getElementById(" ") 得到的是一个对象
    style.top 设置或获取对象相对于文档层次中下个定位对象的上边界的位置offsetTop:返回一个数值,指明了当前元素的上边缘到其offsetTop属性返回的对象的上边缘的距离,即:top+padding+border+margin。我觉得那个写法应该可以。缺少对象应该只能下面地方写错了:
    varId = window.setInterval("moveAd()",moveSpeed);  //启动飘浮 
    -->>> 
    varId = window.setInterval("move_ad()",moveSpeed);  //启动飘浮 
      

  2.   

    1楼的昏 我就这个varId = window.setInterval("moveAd()",moveSpeed);  //启动飘浮
    -->>>
    varId = window.setInterval("move_ad()",moveSpeed);  //启动飘浮
    看错了你的那个代码,没有任何作用
    var ad_Left_Top=parseInt(document.getElementById('float_left').offsetTop);
    var ad_Right_Top=parseInt(document.getElementById('float_right').offsetTop);
    var ad_LHeight=parseInt(document.getElementById('float_left').clientHeight);
    var ad_RHeight=parseInt(document.getElementById('float_right').clientHeight); 
    而且还说我编程风格太乱,你看你自己都不知道自己错在哪里,clientHeight 、offsetTop得到明明都是个数值,还需要你加parseInt个函数干吗?我原来是专门搞这JS的,大部分脚本属性 我基本上了解,而且我这样写代码是最好的习惯和风格,太能装了吧,你.你要是搞定了,再发资格说话.
      

  3.   

    呵呵,你这语气
    其实人家说得没错
    给你看看:<!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>
    <style>
    body,table,td,form,input,ul,li,div,img,select{ 
    margin:0; 
    padding:0; 
    font-size:14px; 
    color: #000000; 
    font-family: "宋体"; 

    #float_left { 
    position: absolute; 
    width: 88px; 
    left: 12px; 
    top: 163px; 
    height: 200px; 
    border: 1px solid #0099FF; 
    padding-top:5px; 

    #float_left .l_close { 
    color:#FF0000; 

    #float_right { 
    position: absolute; 
    width: 88px; 
    top: 163px; 
    border: 1px solid #0099FF; 
    height: 200px; 
    right: 12px; 
    padding-top:5px; 

    </style>
    </head>
    <body style="height:1000px;"><script>
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    function close_ad() { 
    document.getElementById('float_left').style.display='none'; 
    document.getElementById('float_right').style.display='none'; 

    document.write(" <div id='float_left'>背景图片 <hr width='82' align='center' size='0'> <br />越狱 <input type='radio' name='bg' value='pb' onclick='change_bg_color()' checked='true'> <br />熊猫 <input type='radio' name='bg' value='panda' onclick='change_bg_color()'> <br />主妇 <input type='radio' name='bg' value='wives'  onclick='change_bg_color()'> <br />歌星 <input type='radio' name='bg' value='avil'  onclick='change_bg_color()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div> <br> <div id='float_right'>页面风格 <hr width='82' align='center' size='0'> <br />默认 <input type='radio' name='style' value='blue' onclick='change_css()' checked='true'> <br />紫色 <input type='radio' name='style' value='purple' onclick='change_css()'> <br />褐色 <input type='radio' name='style' value='brown'  onclick='change_css()'> <br />橙色 <input type='radio' name='style' value='orange'  onclick='change_css()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div>") ;//根据显示尺寸显示两侧广告 
    function float_ad() { 
    if(document.body.clientWidth>800) { 
    document.getElementById("float_left").style.visibility='visible';
    document.getElementById("float_right").style.visibility='visible'; 

    else{ 
    document.getElementById("float_left").style.visibility='hidden' ;
    document.getElementById("float_right").style.visibility='hidden' ;


    function move_ad(){ 
    var _stepx=2;_stepy=2; //初始化每次偏离的象素 
    var _stepx=2;_stepy=2; //初始化每次偏离的象素 
    var ad_Left_Top=parseInt(document.getElementById('float_left').offsetTop); 
    var ad_Right_Top=parseInt(document.getElementById('float_right').offsetTop); 
    var ad_LHeight=parseInt(document.getElementById('float_left').clientHeight); 
    var ad_RHeight=parseInt(document.getElementById('float_right').clientHeight); 
    var _bodyTop=document.body.scrollTop;
    var _bodyHeight=document.body.clientHeight+_bodyTop; 
    if(ad_Left_Top <=_bodyTop) 
                { 
                  _stepy=2; 
                } 
    if((ad_Left_Top+ad_LHeight)>=_bodyHeight) 
                { 
                  _stepy=-2; 
                } 
    document.getElementById('float_left').style.top=parseInt(ad_Left_Top+_stepy)+"px"; 
    document.getElementById('float_right').style.top=parseInt(ad_Right_Top+_stepy)+"px"; 

    function beginMoveAd()    { 
    var moveSpeed=40;//速度 
    var varId;//获取setInterval的ID 
    varId = window.setInterval("move_ad()",moveSpeed);  //启动飘浮 
    }  
    float_ad()
    window.onload=beginMoveAd; 
    window.onresize=float_ad; //根据显示尺寸调整广告  
    //显示两侧广告 </script>
    </body>
    </html>
      

  4.   

    睡不着,上来再唠叨2句你的文档使用了<!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">
    所以你的var _bodyTop=document.body.scrollTop;
    var _bodyHeight=document.body.clientHeight+_bodyTop; 
    是不正确的,应该改为
    var _bodyTop=document.documentElement.scrollTop;
    var _bodyHeight=document.documentElement.clientHeight+_bodyTop; 
      

  5.   

    不过我觉得,你可能真正要的效果是下面这个:
    <!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>
    <style>
    body,table,td,form,input,ul,li,div,img,select{ 
    margin:0 auto; 
    padding:0; 
    font-size:14px; 
    color: #000000; 
    font-family: "宋体"; 

    #float_left { 
    position: absolute; 
    width: 88px; 
    left: 12px; 
    top: 163px; 
    height: 200px; 
    border: 1px solid #0099FF; 
    padding-top:5px; 

    #float_left .l_close { 
    color:#FF0000; 

    #float_right { 
    position: absolute; 
    width: 88px; 
    top: 163px; 
    border: 1px solid #0099FF; 
    height: 200px; 
    right: 12px; 
    padding-top:5px; 

    </style>
    </head>
    <body>
    <script>
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var startY = 400;//初始值
    var t;//获取setTimeout的ID 
    function close_ad() { 
    document.getElementById('float_left').style.display='none'; 
    document.getElementById('float_right').style.display='none'; 

    document.write(" <div id='float_left'>背景图片 <hr width='82' align='center' size='0'> <br />越狱 <input type='radio' name='bg' value='pb' onclick='change_bg_color()' checked='true'> <br />熊猫 <input type='radio' name='bg' value='panda' onclick='change_bg_color()'> <br />主妇 <input type='radio' name='bg' value='wives'  onclick='change_bg_color()'> <br />歌星 <input type='radio' name='bg' value='avil'  onclick='change_bg_color()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div> <br> <div id='float_right'>页面风格 <hr width='82' align='center' size='0'> <br />默认 <input type='radio' name='style' value='blue' onclick='change_css()' checked='true'> <br />紫色 <input type='radio' name='style' value='purple' onclick='change_css()'> <br />褐色 <input type='radio' name='style' value='brown'  onclick='change_css()'> <br />橙色 <input type='radio' name='style' value='orange'  onclick='change_css()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div>") ;//根据显示尺寸显示两侧广告 
    function float_ad() { 
    if(document.body.clientWidth>800) { 
    document.getElementById("float_left").style.visibility='visible';
    document.getElementById("float_right").style.visibility='visible'; 

    else{ 
    document.getElementById("float_left").style.visibility='hidden' ;
    document.getElementById("float_right").style.visibility='hidden' ;


    function move_ad(){ 
    var y = ns ? pageYOffset + innerHeight : document.documentElement.scrollTop + document.documentElement.clientHeight;
    y -= startY;
    var pY =ns ? pageYOffset + innerHeight : document.documentElement.scrollTop +document.documentElement.clientHeight;
    y += (pY - startY - y)/8;
    document.getElementById('float_left').style.top=parseInt(y)+"px"; 
    document.getElementById('float_right').style.top=parseInt(y)+"px"; 

    function beginMoveAd()    { 
    var moveSpeed=40;//速度 
    var varId;//获取setInterval的ID 
    varId = window.setInterval("move_ad()",moveSpeed);  //启动飘浮 
    }  
    float_ad()
    window.onload=beginMoveAd; 
    window.onresize=float_ad; //根据显示尺寸调整广告  
    //显示两侧广告 </script>
    <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 /><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 /><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 /><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 /><br /><br /><br />
    </body>
    </html>
      

  6.   

    嘿嘿
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    直接删掉这句估计就行了
      

  7.   

    我不以为:chinmo 说的有错
    向你这样的人还说自己从大学开始搞CS.
    我靠。是专业搞:W3C的工程师。那就应该知道在W3C的页面。JS是不能:
    document.body
    就要改成:
    document.documentElement
    这点常识的没有啊。。怀疑你的到底是不是搞W3C。。
    还有。帮你了。还这样说。。
    BS你这种人。。
      

  8.   

    我拿一本javaScript权威指南,看你们在这儿玩.
      

  9.   

    1、命名方式统一
    一会用下划线分隔一会用大小写分隔
    如:move_ad、beginMoveAd2、代码递进
    要么就全不递进,可以理解成压缩
    要么递进的空白字符数要一样
    如:大部分没有递进,偶尔还出现,还长短不一
                { 3、运算符和标识符间空白字符
    要么就全有,要么就全没有
    如:也是长短不一
    if(ad_Left_Top <=_bodyTop)
                  ^
    function beginMoveAd()    { 
                          ^^^^4、N长的字符串
    document.write(" <div id='float_left'>背景图片 <hr width='82' align='center' size='0'> <br />越狱 <input type='radio' name='bg' value='pb' onclick='change_bg_color()' checked='true'> <br />熊猫 <input type='radio' name='bg' value='panda' onclick='change_bg_color()'> <br />主妇 <input type='radio' name='bg' value='wives'  onclick='change_bg_color()'> <br />歌星 <input type='radio' name='bg' value='avil'  onclick='change_bg_color()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div> <br> <div id='float_right'>页面风格 <hr width='82' align='center' size='0'> <br />默认 <input type='radio' name='style' value='blue' onclick='change_css()' checked='true'> <br />紫色 <input type='radio' name='style' value='purple' onclick='change_css()'> <br />褐色 <input type='radio' name='style' value='brown'  onclick='change_css()'> <br />橙色 <input type='radio' name='style' value='orange'  onclick='change_css()'> <p> <br /> <br /> </p> <a href='#' onclick='close_ad()'> <span class='l_close'>关闭 </span> </a> </div>") ;-------
    其实我只是想让你更进一般步!楼主我看好你哟!