Javascript是客户端脚本语言,而VB.net是服务器端的,怎么翻译?

解决方案 »

  1.   

    把Javascript当作string用vb.net代码发送到客户端,可以用Page.RegisterClientScriptBlock或者Page.RegisterStartUpScript等方法。
      

  2.   

    我用VBS写的。
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
    <script language="VBscript" >
      const headHeight=22,bodyHeight=202
      const objCount=4, step=10 
      dim bolMoving  
      bolMoving=false
       <!--                                       -->
       sub showme(obj1,obj2)
         for i=0 to document.all.tags("td").length-1 
       if(left(document.all.tags("td")(i).classname,Len(document.all.tags("td")(i).classname)-1)="headtd") then
              document.all.tags("td")(i).classname="headtd1"     
      end if
     next
     obj2.classname="headtd2"
     moveme(obj1)
       end sub
      <!--`                                     -->
       sub moveme(obj)
          idnumber=Cint(mid(obj.id,5,1))
      objtop=(idnumber-1)*headheight
      objbottom=bodyheight+headheight*(idnumber-2)
      currenttop=Cint(left(obj.style.top,len(obj.style.top)-2))
      if(currenttop>=objbottom) then
        for i=1 to document.all.tags("div").length-1 
      if(document.all.tags("div")(i).id="item"&i&"body") then
         if(i<=idnumber) then
       moveup(document.all.tags("div")(i))
         end if
      end if
        next 
       elseif(currenttop<=objbottom) then
         for i=document.all.tags("div").length-1 to 1 step -1
       if(document.all.tags("div")(i).id="item"&i&"body") then
          if(i>idnumber) then
        movedown(document.all.tags("div")(i))
      end if
       end if
     next 
     end if  
      end sub
     <!--                                                             -->
        sub moveup(obj)
          currenttop=Cint(left(obj.style.top,len(obj.style.top)-2))
      idnumber=Cint(mid(obj.id,5,1))
      if (currenttop>22*(idnumber-1)) then
       currenttop=currenttop-step
       obj.style.top=currenttop
       call settimeout("moveup("+obj.id+")",1) 
     end if
       end sub
     <!--                                  -->  
       sub movedown(obj)
         currenttop=Cint(left(obj.style.top,len(obj.style.top)-2))
     idnumber=Cint(mid(obj.id,5,1))
     objbottom=bodyheight+headheight*(idnumber-2)
     if(currenttop<objbottom) then
         currenttop=currenttop+step
     obj.style.top=currenttop
     call settimeout("movedown("+obj.id+")",1)
      end if
    end sub 
    </script>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type='text/css'>
    .headtd1 {  background: #00A4E1; border: 2px outset; border-color: #00BBFF #0077FF #0077FF #00BBFF; cursor: hand; font-size: 9pt}
    .headtd2 {  background: #20C1FF; border: 2px outset; border-color: #60D3FF #0077FF #0077FF #60D3FF; cursor: hand; font-size: 9pt}
    .bodytd  {
    background: #99CCFF;
    border: 2px outset;
    border-color: #B0D8FF #0077FF #0077FF #B0D8FF;
    font-size: 9pt;
    }
    </style>
    <link href="CSS/POS" rel="stylesheet" type="text/css">
    </head>
    <body bgcolor='#FFFFFF' text='#000000'>
    <div id='mainboard' style='position:absolute; left:0px; top:93px; width:120px; height:268px;z-index:1; overflow: hidden; background: #99CCFF;' class="bodytd"> 
      <div id='item1body' style='position:absolute; left:0px; top:0px; width:120px; height:202px;z-index:2; overflow: hidden'> 
        <table width='100%' border='0' height='100%' cellpadding='2' cellspacing='0'>
          <tr> 
            <td id='item1head' height='20' class='headtd2' align='center' onClick="call showme(item1body,item1head)" >校办发文 
            </td>
          </tr>
          <tr> 
            <td class='bodytd' align='center'>test1</td>
          </tr>
        </table>
      </div>
      <div id='item2body' style='position:absolute; left:0px; top:202px; width:120px; height:202px;z-index:3; overflow: hidden'> 
        <table width='100%' border='0' height='100%' cellpadding='2' cellspacing='0'>
          <tr>
            <td id='item2head' height='20' class='headtd1'  align='center' onClick="call showme(item2body,item2head)">菜单2 
            </td>
          </tr>
          <tr> 
            <td class='bodytd' align='center'>test2</td>
          </tr>
        </table>
      </div>
      <div id='item3body' style='position:absolute; left:0px; top:224px; width:120px; height:202px;        z-index:4; overflow: hidden'> 
        <table width='100%' border='0' height='100%' cellpadding='2' cellspacing='0'>
          <tr>
            <td id='item3head' height='20' class='headtd1' align='center' onClick="call showme(item3body,item3head)">菜单3 
            </td>
          </tr>
          <tr> 
            <td class='bodytd' align='center'>test</td>
          </tr>
        </table>
      </div>
      <div id='item4body' style='position:absolute; left:0px; top:246px; width:120px; height:202px;z-index:5; overflow: hidden'> 
        <table width='100%' border='0' height='100%' cellpadding='2' cellspacing='0'>
          <tr> 
            <td id='item4head' height='20' class='headtd1' align='center' onClick="call showme(item4body,item4head)">菜单4 
            </td>
          </tr>
          <tr>
            <td class='bodytd' align='center'>test</td>
          </tr>
        </table>
      </div>
    </div>
    <p></p> <br>
    <br>
    <br>
    <br>
    <hr align="left" size="7" color="#0066CC" class="POS" >
    </body>
    </html>
      

  3.   

    不管你用vbscript还是Javascript,你都必须把脚本发送到客户端,因为这是客户端脚本,是在客户端运行的。