日期:2014-05-16  浏览次数:20382 次

使用js提交form表单
今天郁闷半天,最后发现使用了
     <input  type="submit" name="submit" value="登录">
之后再使用
document.getElementById("login").submit();
就无法submit。

例如:
<script type="text/javascript">
function form_submit(){
document.getElementById('login').action="";
document.getElementById('login').submit();
}
</script>
<form id="login" name="login" action="" method="get">

    <div id="center_middle">
      <div class="user">
        <label for="username">用户名:
        <input type="text" name="username" id="username" value=""/>
        </label>
      </div>
      <div class="user">
        <label for="password">密 码:
        <input type="password" name="password" id="password" value=""/>
        </label>
      </div>
    </div>
    <div id="center_submit">
      <input  type="submit" name="submit" value="登录">
      <input  type="reset" name="reset" value="重置">
      <input type="button" name="bt" value="bt" onclick="form_submit()">
    </div>
</form>

这样使用js是无法提交的。但是去掉<input  type="submit" name="submit" value="登录">
就没问题了。