当单击第一个表单的"File"按钮之后,再单击三次"提交一"才能进行表单提交;而单击第二个表单的"File"按钮,再单击两次"提交二"按钮才能提交,各位高手知道是什么原因吗?<form action="http://www.baidu.com">
<input type="file" name="j" style="display: none;" onchange="ye.value=value">
<input name="ye" style="color: green;border: 1px solid green">
  <input type="button" value="File" onclick="j.click()" style="border: 1px solid green">
  <input type="button" onclick="document.forms(0).submit()" value="提交一"/>
</form>

<br />
<form action="http://www.google.cn">
<input type="file" name="j" style="display: none;" onchange="ye.value=value">
<input name="ye" style="color: green;border: 1px solid green">
  <input type="button" value="File" onclick="j.click()" style="border: 1px solid green">
  <input type="submit" value="提交二"/>
</form>
怎么写js代码,才能做到单击一次提交钮就是进行表单提交?

解决方案 »

  1.   


    <html>
    <head>
    <title></title>
    </head>
    <body>
    <form action="http://www.google.cn">
    <input type="file" id="f" style="display:none;" onchange="document.getElementById('Y').value=this.value">
    <input type="text" id="Y" style="color: green;border: 1px solid green">
    <input type="button" value="File" onclick="document.getElementById('f').click();" style="border:1px solid green">
    <input type="submit" value="提交">
    </form>

    </body>
    </html>
    <!-- 标签规范,并且name 替换为id ,'例子一' 一样替换就OK .本地测试通过 -->
      

  2.   

    file  必须存在name属性才可以有效的提交。否则,就算提交发出,服务端也收不到.