2016-12-28 60 views
0

我正好卡在有點尷尬situation.I正在使用引導模式在我page.previously舊的數據顯示形式,每個我開模時間得到保留。所以我在我的代碼中加入這一行自舉模態不顯示數據

$(".modal").on("hidden.bs.modal", function(){ 
    $(".modal-body").html(""); 
}); 

現在第一次它顯示正確的數據,但以後它沒有顯示在我的模型什麼第二次。下面是我的模型代碼

<div class="modal fade" id="myModal" 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" id="closeTab" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
       <h4 class="modal-title" id="myModalLabel">add holiday</h4> 
      </div> 

      <div class="modal-body"> 
      <form action="" id="holidayForm"> 
      <h3> <label id="addHoliday"><span class="label label-info">date</span></label> </h3> 

      <h3> <label id="holidayDetail"><span class="label label-info">description</span></label> </h3> 
       <input class="form-control input-lg" id="inputlg" placeholder="description" type="text"> 
       </form> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" id="close" class="btn btn-default" data-dismiss="modal">Close</button> 
       <button type="submit" id="saveChanges" class="btn btn-primary">Save changes</button> 
      </div> 

     </div> 
    </div> 
</div> 

這碼彈出引導

$('.clickMe').click(function(){ 
    var clickId=$(this).attr('id'); 
    var myDate=clickId.toString().substr(0,2); 
    var myMonth=clickId.toString().substr(2,4); 
    $("#addHoliday").append("<h3><input type='text' name='newDate' disabled='disabled' id='newDate'value="+this_year+"-"+myMonth+"-"+myDate+"></input></h3>"); 
    $("#myModal").modal('show'); 


}) 

請讓我知道什麼是錯的

+0

的$( 「模體 」)HTML(「」)。正在清除包含addHoliday的.modal-body內的所有內容,因此下次單擊該按鈕時#addHoliday不再存在。 – abbottmw

+0

那麼如何解決這個問題,如果我刪除了這一行的舊數據關閉模式 –

回答

0

一個快速的解決方案......

要清除出表單域,你可以做這樣的事情

$(".modal").on("hidden.bs.modal", function(){ 
    $(".modal-body #holidayForm input").val(""); 
}); 

你每次點擊.clickMe事件被觸發時追加新的輸入字段。我把那個HTML代碼在你想要的.modal體的輸入字段,然後更換追加到#addHoliday行這樣的事情..

$(".modal-body #holidayForm #newDate").val(this_year + "-" + myMonth + "-" + myDate); 
$(".modal-body #holidayForm #inputlg").val(""); 

UPDATE

在回覆您的評論時,請將模態體中#addHoliday的html更改爲此。

  <h3> 
      <label id="addHoliday"> 
      <span class="label label-info">date</span> 
      <h3><input type="text" name="newDate" id="newDate" value=""/></h3> 
      </label> 
     </h3> 

這種方式你一個newDate輸入字段,然後單擊事件正在更新中.modal體

有意義的那場?

+0

如果我更換追加行那麼它沒有顯示日期字段在所有 –

+0

這裏後,沒有被清除是[的jsfiddle(https://jsfiddle.net/abbottmw/ymdtbLgr /)我在說什麼。 – abbottmw