<script language="javascript" type="text/javascript"> 
 <!-- // 对联广告代码开始 
        var showad = true; 
        var Toppx = 100; //上端位置 
        var AdDivW = 110; //宽度 
        var AdDivH = 6; //高度 
        var PageWidth = 800; //页面多少宽度象素下正好不出现左右滚动条 
        var MinScreenW = 1024; //显示广告的最小屏幕宽度象素         var ClosebuttonHtml = '<div align="right" style="position: absolute;top:0px;right:0px;margin:0px;padding:0px;z-index:2000;"><a href="javascript:;" onclick="hidead()" style="color:white;text-decoration:none;font-size:12px;">关闭</a></div>' 
        var AdContentHtml1 = '<img border="0" src="http://img.baidu.com/img/logo-zhidao.gif">'; //指定左侧的广告图片位置 
        var AdContentHtml2 = '<img border="0" src="http://img.baidu.com/img/logo-zhidao.gif">'; //指定右侧的广告图片位置 
      
    
         document.write ('<div id="Javascript.LeftDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+'<div>'+AdContentHtml1+'</div></div>'); 
         document.write ('<div id="Javascript.RightDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+'<div>'+AdContentHtml2+'</div></div>'); 
         window.onscroll=scall; 
         window.onresize=scall; 
         window.onload=scall; 
       
        function scall()
        { 
            if(!showad){return;} 
            if (window.screen.width<MinScreenW)
            { 
                alert("临时提示:\n\n显示器分辨率宽度小于"+MinScreenW+",不显示广告"); 
                showad = false; 
                document.getElementById("Javascript.LeftDiv").style.display="none"; 
                document.getElementById("Javascript.RightDiv").style.display="none"; 
                return; 
            } 
            var Borderpx = ((window.screen.width-PageWidth)/2-AdDivW)/2; 
            document.getElementById("Javascript.LeftDiv").style.display=""; 
            document.getElementById("Javascript.LeftDiv").style.top=document.body.scrollTop+Toppx; 
            document.getElementById("Javascript.LeftDiv").style.left=document.body.scrollLeft+Borderpx; 
            document.getElementById("Javascript.RightDiv").style.display=""; 
            document.getElementById("Javascript.RightDiv").style.top=document.body.scrollTop+Toppx; 
            document.getElementById("Javascript.RightDiv").style.left=document.body.scrollLeft+document.body.clientWidth-document.getElementById("Javascript.RightDiv").offsetWidth-Borderpx; 
        }         function hidead() 
        { 
            showad = false; 
            document.getElementById("Javascript.LeftDiv").style.display="none"; 
            document.getElementById("Javascript.RightDiv").style.display="none"; 
        } 
   </script>
上面事一段对联广告的代码?我想把这一段代码包含在一个JS文件里面然后用一个Function调用他们
调用的时候 可以传入参数设置这个对联广告参数: 左边图片 ,右边图片,图片高,图片宽,离顶部的距离 

解决方案 »

  1.   

    你写个function aaa(A,B,C,D),把内容包进去不就可以了咩
      

  2.   


    function setshowad(leftpic,rightpic,AdW,AdH,AdTop)
    {
          var showad = true; 
            var Toppx = AdTop; //上端位置 
            var AdDivW = leftpic; //宽度 
            var AdDivH = rightpic; //高度 
            var PageWidth = 800; //页面多少宽度象素下正好不出现左右滚动条 
            var MinScreenW = 1024; //显示广告的最小屏幕宽度象素         var ClosebuttonHtml = ' <div align="right" style="position: absolute;top:0px;right:0px;margin:0px;padding:0px;z-index:2000;"> <a href="javascript:;" onclick="hidead()" style="color:white;text-decoration:none;font-size:12px;">关闭 </a> </div>' 
            var AdContentHtml1 = ' <img border="0" src="+ leftpic +">'; //指定左侧的广告图片位置 
            var AdContentHtml2 = ' <img border="0" src="+ rightpic +">'; //指定右侧的广告图片位置 
          
        
            document.write (' <div id="Javascript.LeftDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml1+' </div> </div>'); 
            document.write (' <div id="Javascript.RightDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml2+' </div> </div>'); 
            window.onscroll=scall; 
            window.onresize=scall; 
            window.onload=scall; 
          
            function scall() 
            { 
                if(!showad){return;} 
                if (window.screen.width <MinScreenW) 
                { 
                    alert("临时提示:\n\n显示器分辨率宽度小于"+MinScreenW+",不显示广告"); 
                    showad = false; 
                    document.getElementById("Javascript.LeftDiv").style.display="none"; 
                    document.getElementById("Javascript.RightDiv").style.display="none"; 
                    return; 
                } 
                var Borderpx = ((window.screen.width-PageWidth)/2-AdDivW)/2; 
                document.getElementById("Javascript.LeftDiv").style.display=""; 
                document.getElementById("Javascript.LeftDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.LeftDiv").style.left=document.body.scrollLeft+Borderpx; 
                document.getElementById("Javascript.RightDiv").style.display=""; 
                document.getElementById("Javascript.RightDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.RightDiv").style.left=document.body.scrollLeft+document.body.clientWidth-document.getElementById("Javascript.RightDiv").offsetWidth-Borderpx; 
            }         function hidead() 
            { 
                showad = false; 
                document.getElementById("Javascript.LeftDiv").style.display="none"; 
                document.getElementById("Javascript.RightDiv").style.display="none"; 
            } }
      

  3.   

    到是能显示出来了。但是对联不上下活动了
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
      <script type="text/javascript" src="js/duilian.js" ></script>
       <script type="text/javascript">
       <!--
            setshowad("300","300","http://www.baidu.com/img/baidu.gif","http://www.baidu.com/img/baidu.gif","100");
       -->
       </script>
    </head>
    <body>
        <form id="form1" runat="server">
        </form>
    </body>
    </html>
      

  4.   

    页面高度为零,当然不能活动,加几个<br>试试;<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"> 
        <title>无标题页 </title> 
      <script type="text/javascript" src="js/duilian.js" > </script> 
      <script type="text/javascript"> 
      <!-- 
            setshowad("300","300","http://www.baidu.com/img/baidu.gif","http://www.baidu.com/img/baidu.gif","100"); 
      --> 
      </script> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        </form> 
    </body> 
    </html> 
      

  5.   

    哟,那个图片高,图片宽是指的图片的偏移量,错了,改进下:
    function setshowad(leftpic,rightpic,AdW,AdH,AdTop)
    {
          var showad = true; 
            var Toppx = AdTop; //上端位置 
            var AdDivW = 110; //宽偏移量 
            var AdDivH = 6; //高偏移量
            var PageWidth = 800; //页面多少宽度象素下正好不出现左右滚动条 
            var MinScreenW = 1024; //显示广告的最小屏幕宽度象素         var ClosebuttonHtml = ' <div align="right" style="position: absolute;top:0px;right:0px;margin:0px;padding:0px;z-index:2000;"> <a href="javascript:;" onclick="hidead()" style="color:white;text-decoration:none;font-size:12px;">关闭 </a> </div>' 
            var AdContentHtml1 = ' <img border="0" src="+ leftpic +" width="+ AdW +" height="+ AdH +">'; //指定左侧的广告图片位置 
            var AdContentHtml2 = ' <img border="0" src="+ rightpic +" width="+ AdW +" height="+ AdH +">'; //指定右侧的广告图片位置 
          
        
            document.write (' <div id="Javascript.LeftDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml1+' </div> </div>'); 
            document.write (' <div id="Javascript.RightDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml2+' </div> </div>'); 
            window.onscroll=scall; 
            window.onresize=scall; 
            window.onload=scall; 
          
            function scall() 
            { 
                if(!showad){return;} 
                if (window.screen.width <MinScreenW) 
                { 
                    alert("临时提示:\n\n显示器分辨率宽度小于"+MinScreenW+",不显示广告"); 
                    showad = false; 
                    document.getElementById("Javascript.LeftDiv").style.display="none"; 
                    document.getElementById("Javascript.RightDiv").style.display="none"; 
                    return; 
                } 
                var Borderpx = ((window.screen.width-PageWidth)/2-AdDivW)/2; 
                document.getElementById("Javascript.LeftDiv").style.display=""; 
                document.getElementById("Javascript.LeftDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.LeftDiv").style.left=document.body.scrollLeft+Borderpx; 
                document.getElementById("Javascript.RightDiv").style.display=""; 
                document.getElementById("Javascript.RightDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.RightDiv").style.left=document.body.scrollLeft+document.body.clientWidth-document.getElementById("Javascript.RightDiv").offsetWidth-Borderpx; 
            }         function hidead() 
            { 
                showad = false; 
                document.getElementById("Javascript.LeftDiv").style.display="none"; 
                document.getElementById("Javascript.RightDiv").style.display="none"; 
            } }
      

  6.   

    测试下可以了,lz自己再试试:<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    var showad = true; 
    var AdDivW = 110; //宽偏移量 
    var AdDivH = 6; //高偏移量
    var PageWidth = 800; //页面多少宽度象素下正好不出现左右滚动条 
    var MinScreenW = 1024; //显示广告的最小屏幕宽度象素 
    function setshowad(leftpic,rightpic,AdW,AdH,AdTop)
    {
            var ClosebuttonHtml = ' <div align="right" style="position: absolute;top:0px;right:0px;margin:0px;padding:0px;z-index:2000;"> <a href="javascript:;" onclick="hidead()" style="color:white;text-decoration:none;font-size:12px;">关闭 </a> </div>' 
            var AdContentHtml1 = "<img border=0 src='"+ leftpic +"' width='"+ AdW +"' height='"+ AdH +"'>"; //指定左侧的广告图片位置 
            var AdContentHtml2 = "<img border=0 src='"+ rightpic +"' width='"+ AdW +"' height='"+ AdH +"'>"; //指定右侧的广告图片位置 
            document.write (' <div id="Javascript.LeftDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml1+' </div> </div>'); 
            document.write (' <div id="Javascript.RightDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+' <div>'+AdContentHtml2+' </div> </div>'); 
            window.onscroll=function()
    {
       scall(AdTop);

            window.onresize==function()
    {
       scall(AdTop);
    }       
    }
    function scall(Toppx) 

                if(!showad){return;} 
                if (window.screen.width <MinScreenW) 
                { 
                    alert("临时提示:\n\n显示器分辨率宽度小于"+MinScreenW+",不显示广告"); 
                    showad = false; 
                    document.getElementById("Javascript.LeftDiv").style.display="none"; 
                    document.getElementById("Javascript.RightDiv").style.display="none"; 
                    return; 
                } 
                var Borderpx = ((window.screen.width-PageWidth)/2-AdDivW)/2; 
                document.getElementById("Javascript.LeftDiv").style.display=""; 
                document.getElementById("Javascript.LeftDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.LeftDiv").style.left=document.body.scrollLeft+Borderpx; 
                document.getElementById("Javascript.RightDiv").style.display=""; 
                document.getElementById("Javascript.RightDiv").style.top=document.body.scrollTop+Toppx; 
                document.getElementById("Javascript.RightDiv").style.left=document.body.scrollLeft+document.body.clientWidth-document.getElementById("Javascript.RightDiv").offsetWidth-Borderpx; 
     }  function hidead() 

              showad = false; 
              document.getElementById("Javascript.LeftDiv").style.display="none"; 
              document.getElementById("Javascript.RightDiv").style.display="none"; 
    } setshowad("http://www.baidu.com/img/baidu.gif","http://www.baidu.com/img/baidu.gif","100","300",100); 
    scall(100);</script>
    </head><body>
    <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>
      

  7.   

    把scall(100);放在setshowad函数的最后面也可以.