阻止form表单提交的常用方式

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-22 15:17   11   0

>给form标签的添加表单提交事件οnsubmit="return false;"

<form onsubmit="return change()" id="myForm" method="POST" class="form-horizontal" role="form"> 
</form> 
<script> 
function change() {       //动作:阻止表单数据提交     return false; } 
</script>

>JavaScript给form表单中的按钮添加单击事件οnclick="return false;"

<form onsubmit="" id="myForm" method="POST" class="form-horizontal" role="form">     

<button class="btn btn-primary" type="submit" onclick="return change();">提交</button>
</form> 
<script> 
function change() {         
//动作:阻止表单数据提交     return false;
} 
</script>

>Jquery 给form标签添加表单提交事

<form id="myForm" method="POST" class="form-horizontal" role="form">
</form> 
<script>
 $('#myForm').submit(function (event) {  
     event.preventDefault();              
     return false;     
   // 直接在事件处理程序中返回false          
});
</script>

>规定button的类型为button,使用click事件触发,逻辑后手动提交;

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP