有事没事领个红包

前端表单中有按钮button自动提交表单

问题描述

在设计表单时,表单内有一个按钮<button>,该按钮是用来获取其他数据或执行其他操作的。并不是让他提交表单。

解决方案

1) 设置 form 的 onsubmit='return false';

2)将按钮改成如下格式 <input type="button">

3) 在处理函数中使用

$( "a" ).click(function( event ) {
  event.preventDefault();
  $( "<div>" )
    .append( "default " + event.type + " prevented" )
    .appendTo( "#log" );
});

 

在 vue 中可以使用 prevent 修饰符进行修饰

 

posted @ 2018-08-06 19:03  crazyCodeLove  阅读(754)  评论(0编辑  收藏  举报