前端表单中有按钮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 修饰符进行修饰
学习过程中,难免出错。如果您在阅读过程中遇到不太明白,或者有疑问。欢迎指正...联系邮箱crazyCodeLove@163.com
如果觉得有用,想赞助一下请移步赞助页面:赞助一下

浙公网安备 33010602011771号