BootStrapValidator表单验证插件的坑还真不少,又让我碰上一个…
BootStrapValidator验证的表单中只可有一个type="submit"
的按钮。我这样写了之后(代码如下),点击其它按钮仍会触发验证…
1.错误代码
//示意
<form>
...
<button type="submit">提交</button>
...
<button>重置</button>
<button>取消</button>
...
</form>
一开始是写成这样的,但是问题来了,点击其它的按钮也会触发表单验证…
2.正确代码
//示意
<form>
...
<button type="submit">提交</button>
...
<button type="button">重置</button>
<button type="button">取消</button>
...
</form>
这样写点击除
提交
外的按钮就可以避免触发验证了,<button>
标签的type
属性有三个值,分别是submit
、button
和reset
,在BootStrapValidator的验证表单中只能有一个type=submit
的按钮,如果type
属性不写或为空,那么就会被自动识别为type=submit
,点击时会触发验证。而type=button
可以为多个,所以可以在不需要加验证的按钮给type
属性设为button
就好了。而type=reset
的按钮点击时也会触发验证。
具体的各位读者老爷们可以自行验证…
标签
部署
TFS
WebStorm
GitHub
GitLab
Git
VS Code
HomeBrew
Nginx
Node.js
CentOS
全局变量
Yarn
Windows
terminal
macOS
Ubuntu
Linux
WSL
Bootstrap
Echarts
ArcGIS
GIS
状态码
浏览器
小程序
npm
Webpack
antd
Router
React
Vue
window
ResizeObserver
Web APIs
技巧
盒子模型
Selector
标签
HTML进阶
CSS
Html
Array
export
ES6
ESM
CommonJS
require
import
Object
进阶
JavaScript