onclick="j.click()"这是什么?说明你点第一次时onclick函数没有解析!先考虑函数放置的位置!再验查语法

解决方案 »

  1.   

    重点问题是你的check函数是什么,需要贴出来
      

  2.   

     <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
    你可以把type改成button的,然后把submit放到check()函数里,试试看
    <input name="提交" type="button" class="bu" value="导 入" onClick="check()">
      

  3.   

    check() 函数就是一个简单的判断输入是否为空function check(){
      if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
      {
      alert("文件路径不能为空!")
      return false;
      }
      return true;
    }但是如果文件路劲为空的时候只点击一次就可以出现alert提示框了
      

  4.   

    <input name="提交" type="submit" class="bu" value="导 入" onClick="return check()">
      

  5.   

    把提交触发的事件写在表单里看看
    <from onSubmit="return check();">
      

  6.   

    <input name="提交" type="submit" class="bu" value="导 入" onClick="return check()">
      

  7.   


       <input name="提交" type="submit" class="bu" value="导 入" onClick="check()" causesvalidation=false>
      

  8.   

    function check(){ 
      if(document.form1.filepath.value == null ||document.form1.filepath.value =="") 
      { 
      alert("文件路径不能为空!") 
      return false; 
      } 
      return true; 

       <input name="提交" type="submit" class="bu" value="导 入" onClick="return check();" causesvalidation=false>
      

  9.   


    function check(){
      if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
      {
      alert("文件路径不能为空!")
      return false;
      }
      return true;
    }
    <body style="background-color: #D6EAF2">
    <form name="form1" method="post" action="excelImport.do">
      <table width="100%" height="47"  border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
        <tr>
          <td width="25%" height="25">&nbsp;</td>
          <td><div align="center" class="style1">您可以先下载<a href="&#23454;&#26045;">导入模板</a>,然后按照模板格式导入</div></td>
          <td width="26%">&nbsp;</td>
        </tr>
        <tr >
          <td colspan="3"><div align="center">
      <input type=file name=j style="display: none;" onchange="filepath.value=value">
      <input name="filepath" width="300px" height="10px"> 
      <input name="按钮" type="button" class="bu"  onclick="j.click()" value="浏 览"> 
      <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
      </div></td>
        </tr>
    <tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr>
      </table>
        
    </form>
    </body>这就是全部的代码,按照楼上的方法修改,还是没用
      

  10.   

    <form name="form1" method="post" action="excelImport.do" onsubmit="return check();">
    <input name="提交" type="submit" class="bu" value="导 入">
      

  11.   


    可能大家把我的意思理解错误了,我的意思是:
    在没有往file里面填入路径的时候,点击“导入”按钮只需要点一次就能提示alert对话框“文件路径不能为空!”
    但是如果往file里面填入了路径呢,点击“导入”按钮却要点两下才能提交整个表单
    请问这是为什么,整个代码我都贴上来了,请大家帮帮呀
      

  12.   

    action="excelImport.do" 你这个里面是什么东西!是否有异常发生?
      

  13.   

    这个是struts里的action机制
    没有错误
    我刚才测试了下把其中的一段代码删除掉就不会出现我所说的情况了。
    <input type=file name=j >
      <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
    我把文件域隐藏的浏览按钮再都显示出来,就不会出现这样的情况了
      

  14.   

    你的做法貌似是将file控件的文件路径值放到了hidden中,然后在上传提交。hidden恐怕没这权限吧~~我这里提示是拒绝访问!
      

  15.   

    function check()
    {
      if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
      {
      alert("文件路径不能为空!")
      return false;
      }
      return true;
      //document.getElementByID("aa").submit;
    }<body style="background-color: #D6EAF2">
    <form name="form1" id="aa" method="post" action="excelImport.do">
      <table width="100%" height="47"  border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
        <tr>
          <td width="25%" height="25">&nbsp;</td>
          <td><div align="center" class="style1">您可以先下载<a href="&#23454;&#26045;">导入模板</a>,然后按照模板格式导入</div></td>
          <td width="26%">&nbsp;</td>
        </tr>
        <tr >
          <td colspan="3"><div align="center">
      <input type=file name=j style="display: none;" onchange="filepath.value=value">
      <input name="filepath" width="300px" height="10px"> 
      <input name="按钮" type="button" class="bu"  onclick="j.click()" value="浏 览"> 
      <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
      </div></td>
        </tr>
    <tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"></font></div></td></tr>
      </table>
        
    </form>
    </body>把这段代码去掉试试,<%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%>、或者type="submit"改为type="button"  check()函数加上document.getElementByID("aa").submit;试试
      

  16.   


    点击一次可以提交
    <script type="text/javascript" >
        function check()
    {
      if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
      {
      alert("文件路径不能为空!")
      return false;
      }
      
      document.Form1.submit();
      return true;
    }
        
        
        </script>
    </head>
    <body style="background-color: #D6EAF2">
    <form name="form1" id="Form1" method="post" action="excelImport.do">
      <table width="100%" height="47"  border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
        <tr>
          <td width="25%" height="25">&nbsp;</td>
          <td><div align="center" class="style1">您可以先下载<a href="&#23454;&#26045;">导入模板</a>,然后按照模板格式导入</div></td>
          <td width="26%">&nbsp;</td>
        </tr>
        <tr >
          <td colspan="3"><div align="center">
      <input type=file name=j style="display: none;" onchange="filepath.value=value">
      <input name="filepath" width="300px" height="10px"> 
      <input name="按钮" type="button" class="bu"  onclick="j.click()" value="浏 览"> 
      <input name="提交" type="button" class="bu" value="导 入" onClick="check()">
      </div></td>
        </tr>
    <tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr>
      </table>
        
    </form>
    </body>
      

  17.   

    <input name="提交" type="button" class="bu" value="导 入" onClick="check()">document.Form1.submit();
      

  18.   

    action="excelImport.do"
    把这个贴出来
    excelImport.do时什么东西?
      

  19.   

    会不会是onchange="filepath.value=value">影响了导入按钮的提交
      

  20.   


    就是onchange="filepath.value=value">这段代码影响提交。但是又要靠这段代码来获取上传的路径。
    楼主可能需要换一种方案!