1

我有带有提交按钮的表单。一旦用户点击提交,我想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>

上面的代码将提交按钮移到表单网格之外。我想知道表单内部是否使用任何类将元素组合在同一个网格中?

4

1 回答 1

1

“表单网格外的提交按钮”

它仍然在表格网格内,但只是得到了边距15px

问题是

你给了你的buttoncol-*-2,它给了它margin:15px

解决方案

  1. col-*-2从您的第二个中删除form-group
  2. 为成功消息添加 JS,并为其赋予属性inline-block
  3. 重要- 从类中删除填充.alert

$('#frm_myaccount').submit(function(e) {
  $('#myaccount-message').append("<p style='line-height:0px; color:green; font-weight:700;'>Submit Recorded Successfully!</p>");

  e.preventDefault();
});
.alert {
  padding: 0px !important;
}
<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>

于 2018-03-30T21:44:17.597 回答