如何在Bootstrap twitter中添加表单内的网格?

时间:2018-03-30 20:19:17

标签: twitter-bootstrap twitter-bootstrap-3 twitter-bootstrap-form

我有提交按钮的表单。用户点击“提交”后,我希望在按钮旁边显示Record Successfully saved之类的消息。以下是我的表格示例:

<form name="frm_myaccount" id="frm_myaccount" class="frm-Submit" autocomplete="off">
    <div class="form-group required">
         <label class="control-label" for="answer">Answer</label>
         <input type="text" class="form-control" name="frm_answer" id="frm_answer" placeholder="Enter Answer" maxlength="100" required>
    </div>
    <div>
        <div class="col-xs-2">
             <button type="submit" class="btn btn-primary">Submit</button>
        </div>
        <div class="col-xs-10">
             <div id="myaccount-message" class="alert"></div>
        </div>
    </div>
</form>

上面的代码移动了表格网格之外的提交按钮。我想知道在表单中是否有任何类在同一网格中将元素组合在一起?

1 个答案:

答案 0 :(得分:1)

  

&#34;在表单网格外提交按钮&#34;

它仍在表单网格中,但只有15px

的边距

问题

您已将button课程col-*-2提供给margin:15px

解决方案

  1. 从第二个col-*-2
  2. 中删除form-group
  3. 为成功消息添加JS,并为其提供属性inline-block
  4. 重要 - 从班级.alert
  5. 中删除填充

    &#13;
    &#13;
    $('#frm_myaccount').submit(function(e) {
      $('#myaccount-message').append("<p style='line-height:0px; color:green; font-weight:700;'>Submit Recorded Successfully!</p>");
    
      e.preventDefault();
    });
    &#13;
    .alert {
      padding: 0px !important;
    }
    &#13;
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.3/js/bootstrap.js"></script>
    <form name="frm_myaccount" id="frm_myaccount" class="frm-Submit" autocomplete="off">
      <div class="form-group required">
        <label class="control-label" for="answer">Answer</label>
        <input type="text" class="form-control" name="frm_answer" id="frm_answer" placeholder="Enter Answer" maxlength="100" required>
      </div>
      <div class="form-group">
        <button style="display:inline;" type="submit" id="forrm" class="btn btn-primary">Submit</button>
        <div style="display:inline-block;" id="myaccount-message" class="alert"></div>
      </div>
    </form>
    &#13;
    &#13;
    &#13;