按钮在form表单中时return失效,自动提交后台解决方法

来源:互联网 发布:淘宝精品 编辑:程序博客网 时间:2024/05/22 00:25

按钮在form表单中的问题

1.  代码案例

 <formaction="aaa!edit.action"method="post"enctype="multipart/form-data">

    <tableborder="0"width="85%;"style="font-size: 13px;margin-left: 15px;margin-top:15px;">

        <tr>

            <tdwidth="9%"valign="top"><spanstyle="font-weight:bold;">&nbsp;&nbsp;&nbsp;&nbsp;字:</span><spanstyle="font-weight: bold;">&nbsp;&nbsp;</span></td>

            <td width="91%"><textarearows="7"cols="25"id="key"name="key"></textarea></td>

        </tr>

        ….

        <tr>

            <td></td>

            <tdclass="tdStyle"align="left"valign="bottom"id="contorlHeight" colspan="4">

                  <button class=btnid="save"onClick="formSubmit();">修改</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                  <button class=btnonClick="formReset();">取消</button>

          </td>

        </tr>

    </table>

</form>

 

//form提交

        functionformSubmit(){

            if ($("#key").val().length== 0){

                alert("请输入关键字");

                return;

            }

           

           

           

         $("#save").onclick =function (){return false;};

            document.forms[0].submit();

        }

 

 

问题1:如果按钮在form表单中,那么,即使key中没有值,form表单依旧会提交

问题2:在ie10时会提交两次!

 

解决方法:将按钮放在form表单外面

 

原创粉丝点击