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

2023-10-15,,

问题描述

在设计表单时,表单内有一个按钮<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 修饰符进行修饰

前端表单中有按钮button自动提交表单的相关教程结束。

《前端表单中有按钮button自动提交表单.doc》

下载本文的Word格式文档,以方便收藏与打印。