html中submit和button的区别/ window.location.href 不跳转 的问题

 

  <input type="button">  <input type="submit">ajax

这两个的区别 是浏览器

button 不会自动提交表单数据,只会执行 onclick 里面的事件处理,若是要提交数据,须要加上 document.form1.submit(); 等dom

submit 会自动提交表单数据,使用它的时候要加上验证 ,放回 验证  return ture ; 或 return false;异步

<input type="submit" name="Submit" value="注册" onClick=" return check(); " >orm

<script>事件

 funciotn check()ip

{ci

  验证 知足条件 return ture; get

         不知足条件 return false;input

}

</script>

[     <asp:Button OnClick=""  OnClientClick="return check()" >

 服务端控件 能够加上 OnClientClick 验证。    ]

须要注意的是  <button> </button> 控件 有特殊状况,在Internet Explorer 的默认类型是“button” ,而在其余浏览器中 的默认值时 “Submit” ,用 button 时,要加的规定 Type 值。

可是用到 异步操做, 如 $.ajax()  ,success 后 会跳转页面,当 type=“submit” 时, 没有加验证,执行完 $.ajax () 后,并不会跳转,  会自动提交 表单, 显示的效果就是 刷新了一下, 并不会 跳转到其余页。

例如:

  $("#save").click(function () {
                var supplyvalues = jQuery.map($landlordsupply.filter(":checked"), function (a) {
                    return $(a).val();
                })
 
                $.getJSON("/WebServer/AddHouseInfo.ashx", { "type": "addhousefacility", "facility": supplyvalues.join() }, function (r) {
                    if (r.err == "0") {
                        alert("发布成功");
                        window.location = "SubmitHouse.aspx?ti=" + Math.random();
                    }
                    else {
                        alert(r.err);
                    };
                });
 
                return false; // 必须加上 这句话,才不会继续提交表单, 而且这句话不能加到                            //getJSON() 里面, 异步 加到里面没有做用,只有异步执行完后                               // 加上这句话,作出判断,不会继续执行 Submit.
 
            })
相关文章
相关标签/搜索