Bootstrap 切换避免表单提交
Bootstrap Toggle avoid form submission
我按以下方式使用 bootstrap 切换,但是通过从 YES 更改为 NO 它提交了 from。
<B>Do you want?</B>
<div class="btn-group btn-toggle">
<button class="btn btn-xs btn-default">Yes</button>
<button class="btn btn-xs btn-primary active">No</button>
</div>
表单代码如下:
{% extends 'base.html' %}
{% block body %}
<div class="row clearfix">
<div class="col-md-6 column">
<form class="form-horizontal" action="{{ url_for('tsnps')}}" method="POST" role="form">
{{ fform.hidden_tag() }}
<div class="form-group">
<div class="col-sm-5">
{{ fform.start_pos(class="form-control", placeholder="Start position e.g. 1", type="number")}}
</div>
<div class="col-sm-5">
{{ fform.end_pos(class="form-control", placeholder="End position e.g. 1000", type="number")}}
</div>
</div>
<B>Do you want?</B>
<div class="btn-group btn-toggle">
<button class="btn btn-xs btn-default">Yes</button>
<button class="btn btn-xs btn-primary active">No</button>
</div>
<div class="form-group">
<div class="col-sm-10">
<div class="checkbox">
<label><input type="checkbox" /> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
</div>
{% endblock %}
如何只保存值(YES 或 NO)而避免表单提交?
将按钮的类型更改为 "button"。默认类型是 "submit"(至少在某些浏览器上是这样),它的作用类似于提交输入。
<button type="button" class="btn btn-xs btn-default">Yes</button>
我按以下方式使用 bootstrap 切换,但是通过从 YES 更改为 NO 它提交了 from。
<B>Do you want?</B>
<div class="btn-group btn-toggle">
<button class="btn btn-xs btn-default">Yes</button>
<button class="btn btn-xs btn-primary active">No</button>
</div>
表单代码如下:
{% extends 'base.html' %}
{% block body %}
<div class="row clearfix">
<div class="col-md-6 column">
<form class="form-horizontal" action="{{ url_for('tsnps')}}" method="POST" role="form">
{{ fform.hidden_tag() }}
<div class="form-group">
<div class="col-sm-5">
{{ fform.start_pos(class="form-control", placeholder="Start position e.g. 1", type="number")}}
</div>
<div class="col-sm-5">
{{ fform.end_pos(class="form-control", placeholder="End position e.g. 1000", type="number")}}
</div>
</div>
<B>Do you want?</B>
<div class="btn-group btn-toggle">
<button class="btn btn-xs btn-default">Yes</button>
<button class="btn btn-xs btn-primary active">No</button>
</div>
<div class="form-group">
<div class="col-sm-10">
<div class="checkbox">
<label><input type="checkbox" /> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
</div>
{% endblock %}
如何只保存值(YES 或 NO)而避免表单提交?
将按钮的类型更改为 "button"。默认类型是 "submit"(至少在某些浏览器上是这样),它的作用类似于提交输入。
<button type="button" class="btn btn-xs btn-default">Yes</button>