Javascript阻止表单提交
Javascript阻止表单提交 Html 1.<form name="loginForm" action="login.aspx" method="post"> 2. <button type="submit" value="Submit" id="submit">Submit</button> 3.</form> Js 第一种方法 1.<script> 2. var submitBtn = document.getElementById("submit"); 3. submitBtn.onclick = function (event) { 4. alert("preventDefault!"); 5. return false; 6. }; 7.</script> Js 第二种方法 1.<script> 2. var submitBtn = document.getElementById("submit"); 3. submitBtn.onclick = function (event) { 4. alert("preventDefault!"); 5. var event = event || window.event; 6. event.preventDefault(); // 兼容标准浏览器 7. window.event.returnValue = false; // 兼容IE6~8 8. }; 9.</script> 出处 http://www.dengzhr.com