Bootstrap Toggle避免表单提交

时间:2015-01-05 03:31:53

标签: twitter-bootstrap twitter-bootstrap-3 flask flask-wtforms

我以下列方式使用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)并避免表单提交?

1 个答案:

答案 0 :(得分:2)

将按钮的类型更改为&#34;按钮&#34;。默认类型是&#34;提交&#34; (至少在某些浏览器上),它将像提交输入一样。

<button type="button" class="btn btn-xs btn-default">Yes</button>