当用户单击“保存”时清除模态数据

问题描述 投票:1回答:1

我有一个使用Bootstrap和jQuery的多部分模式向导。当用户进入模态的第3部分并单击“保存”时,我要擦除数据-因为现在当我重新打开模态时,它会重新加载到第3部分,而不是从第1步重新启动这是应该做的。

这是我的HTML:

    <div class="form-group" id="repeat-every-div">
      <label>Repeat Every</label>
      <input type="text" class="job-repeat-every form-control" data-toggle="modal" data-target="#scheduleModal">
    </div>

    <div id="scheduleModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
      aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Recurring Job Steps</h3>
          </div>
          <div class="modal-body" id="myWizard">

            <div class="tab-content">
              <div class="tab-pane fade in active" id="step1">

                <div class="well">

                  <label>Recurring Interval</label>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="daily" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Daily</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="weekly" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Weekly</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="monthly" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Monthly</label>
                  </div>
                </div>
                <!-- <a class="btn btn-default next" href="#step2">Continue</a> -->
                <a class="btn btn-default next" href="#weeklyOptions" data-toggle="tab" data-step="2">Continue</a>
              </div>
              <!-- <div class="tab-pane fade" id="weekly-options"> -->
              <div class="tab-pane fade" id="weeklyOptions">
                <div class="well">
                  <label>Day of the Week</label>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="monday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Monday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="tuesday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Tuesday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="wednesday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Wednesday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="thursday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Thursday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="friday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Friday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="saturday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Saturday</label>
                  </div>
                  <div class="form-check">
                    <input type="radio" class="form-check-input" id="sunday" name="materialExampleRadios">
                    <label class="form-check-label" for="materialUnchecked">Sunday</label>
                  </div>
                </div>
                <a class="btn btn-default next" href="#step3" data-toggle="tab" data-step="3">Continue</a>
              </div>
              <div class="tab-pane fade" id="step3">
                <div class="md-form mx-5 my-5">
                  <input type="time" id="inputMDEx1" class="form-control">
                  <label for="inputMDEx1">Choose your time</label>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            <button class="btn btn-primary" data-dismiss="modal" id="save-recurring-job">Save</button>
          </div>
        </div>
      </div>
    </div>

这是用户单击“保存”按钮时所要调用的内容:

$("#save-recurring-job").click(
  function (event) {
    $("#scheduleModal").removeData();
  }
);

正如我提到的,目前这行不通。当我重新打开模态时,第3部分将重新加载,最后输入的数据仍在那里。当用户单击“保存”时,我该怎么做以清除所有数据?

jquery twitter-bootstrap bootstrap-modal
1个回答
0
投票

要重置数据,您可以将其包装在<form>标记中并调用form reset函数以返回到初始状态。

至于活动选项卡,它似乎使用了active类,因此您可以将该类添加到第一个类,并通过classList.add / classList.remove在关闭(或打开)时从任何其他类中删除。

© www.soinside.com 2019 - 2024. All rights reserved.