<script language=vbscript>
function reg_Onsubmit()
if document.reg.file.value="" then
msgbox "请选择要上传的附件!"
reg_onsubmit=false
exit function
else
document.reg.action="imgs.asp"
end if
end function
</script>请将上面VBS改成JS。
注意document.reg.action="imgs.asp"这句。
谢谢。

解决方案 »

  1.   

    全部程序如下,无法正常运行,也无法转向imgs.asp:<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>选择和上传图片</title>
    <script language=vbscript>
    function reg_Onsubmit()
    if document.reg.file.value="" then
    msgbox "请选择要上传的附件!"
    reg_onsubmit=false
    exit function
    else
    document.reg.action="imgs.asp"
    end if
    end function
    </script><script type="text/javascript">
    function preview4()

    var x = document.getElementById("file"); 
    var y = document.getElementById("pic4"); 
    if(!x || !x.value || !y) return; 
    var patn = /\.jpg$|\.jpeg$|\.gif$/i; 
    if(patn.test(x.value))
    {  y.src = "file://local/" + x.value; }
    else
    {  alert("您选择的似乎不是图像文件。");
    }
    }
    </script></head><body leftmargin="1" topmargin="1">
    <table width="100%" border="1" cellpadding="2" cellspacing="2">
      <tr>
        <td height="149" valign="top"> 
          <table width="100%" border="0">
            <form method="post"  enctype="multipart/form-data" name="reg">
              <tr bgcolor="#B5F0FF"> 
                <td height="25" colspan="2"> &nbsp;<img src="../images/dots.GIF" width="13" height="11"> 
                  选择和上传商品图片(标准大小:110*80)</td>
              </tr>
              <tr> 
                <td width="32%" rowspan="5" valign="middle"> 
                  <div align="right"> 
                    <table width="110" height="80" border="1" align="center" cellpadding="2" cellspacing="2" bgcolor="#E4E4E4">
                      <tr>
                        <td width="490" background="../images/bclass1.gif">&nbsp;</td>
                      </tr>
                    </table>
                  </div></td>
                <td width="68%">&nbsp;</td>
              </tr>
              <tr> 
                <td><div align="center">
                   <input type="file" name="file" id="file" onchange="preview4()">
                  </div></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><div align="center"> 
                    <input type="submit" name="Submit" value="确认上传">
                  </div></td>
              </tr>
              <tr> 
                <td height="20">&nbsp;</td>
              </tr>
            </form>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    <script language=javascript> 
    function reg_Onsubmit() 
    if (document.reg.file.value="") {
    alert("请选择要上传的附件!"); 
    reg_onsubmit=false ;} 
    else 
    document.reg.action="imgs.asp"  
    </script> 
      

  3.   


    <script> 
    function reg_Onsubmit(){
    if(document.reg.file.value==""){
        alert("请选择要上传的附件!" );
    return false 
    }
    else document.reg.action="imgs.asp";
    return true;

    </script> 
    <form name="reg" onsubmit="reg_Onsubmit()" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" >
    </form>
      

  4.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>选择和上传图片</title>
    <script type="text/javascript">
    function reg_Onsubmit(){
        if(document.reg.file.value==""){
            alert("请选择要上传的附件!" );
            return false 
        }
        else document.reg.action="imgs.asp";
        return true;
    } function preview4()

    var x = document.getElementById("file"); 
    var y = document.getElementById("pic4"); 
    if(!x || !x.value || !y) return; 
    var patn = /\.jpg$|\.jpeg$|\.gif$/i; 
    if(patn.test(x.value))
    {  y.src = "file://local/" + x.value; }
    else
    {  alert("您选择的似乎不是图像文件。");
    }
    }
    </script></head><body leftmargin="1" topmargin="1">
    <table width="100%" border="1" cellpadding="2" cellspacing="2">
      <tr>
        <td height="149" valign="top"> 
          <table width="100%" border="0">
            <form method="post"  enctype="multipart/form-data" name="reg" onsubmit="return reg_Onsubmit();">
              <tr bgcolor="#B5F0FF"> 
                <td height="25" colspan="2"> &nbsp;<img src="../images/dots.GIF" width="13" height="11"> 
                  选择和上传商品图片(标准大小:110*80)</td>
              </tr>
              <tr> 
                <td width="32%" rowspan="5" valign="middle"> 
                  <div align="right"> 
                    <table width="110" height="80" border="1" align="center" cellpadding="2" cellspacing="2" bgcolor="#E4E4E4">
                      <tr>
                        <td width="490" background="../images/bclass1.gif">&nbsp;</td>
                      </tr>
                    </table>
                  </div></td>
                <td width="68%">&nbsp;</td>
              </tr>
              <tr> 
                <td><div align="center">
                   <input type="file" name="file" id="file" onchange="preview4()">
                  </div></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><div align="center"> 
                    <input type="submit" name="Submit" value="确认上传">
                  </div></td>
              </tr>
              <tr> 
                <td height="20">&nbsp;</td>
              </tr>
            </form>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>
      

  5.   

    感谢。
    不过是否发现,当按”上传“按钮时,无法转向imgs.asp,请帮忙解决此问题。
      

  6.   

    5楼的代码测试过,可以跳转到 imgs.asp
      

  7.   

    明明有imgs.asp,可是它却是找不到服务器这样:res://C:\WINDOWS\system32\shdoclc.dll/dnserror.htm#http://127.0.0.1/dxlq/gl/imgs.asp
      

  8.   

    代码所在的页面和imgs.asp 放在同一个gl目录下?