1.方式一
<form action="index_submit.do" method="get" accept-charset="utf-8" onclick="return avoidJump()"
>
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">提交</button>
</form>
<script type="text/javascript">
function avoidJump(){
return false;
}
</script>
2.方式二,结合ajax
<form id="postForm" action="upload.php" method="post" onsubmit="javascript:return subfun();" enctype="application/x-www-form-urlencoded">
<p>用户名:<input type="text" name="username"></p>
<p>密 码:<input type="password" name="password"></p>
<p><input type="submit" value="登录"></p>
</form>
<script>
function subfun() {
$.ajax({
url : "upload.php",
type : "POST",
data : $( '#postForm').serialize(),
success : function(data) {
console.info(data);
},
error : function(data) {
console.warn(data);
}
});
return false;
}
</script>