2016-09-30 69 views
0
刪除引導日期選擇器

我的情況是,我有幾個文本框 的我手動與文本框的jQuery無法從文本框

$('#dataRange input').addClass('datepicker'); 
$('.datepicker').datepicker({dateFormat: "yy-mm-dd"}).datepicker("setDate", new Date()).focus(); 

,然後當我嘗試刪除或取消綁定手動添加引導日期選擇器它

$('.datepicker').datepicker('destroy'); 
$(".datepicker").unbind('focus'); 
$('#dataRange input').removeClass('datepicker'); 

那麼我就不能改回日期選擇器與第一碼,日期選擇器下拉框顯示不出來:(

+1

不會刪除只是該類夠嗎? – madalinivascu

+0

@madalinivascu nope –

+1

'我手動添加引導日期時間選擇器'..但我只看到'datepicker' – Viney

回答

0

其在這裏工作請看這個。我認爲你錯過了一些事件。我已添加兩個按鈕例如綁定和解除綁定和點擊事件我已綁定和解除綁定分別datepicker及其工作。檢查我fiddle

$('#dataRange input').addClass('datepicker'); 
 
      $('.datepicker').datepicker({dateFormat: "yy-mm-dd"}).datepicker("setDate", new Date()).focus(); 
 
      $(".unbind").on("click", function() { 
 
       $('.datepicker').datepicker('destroy'); 
 
      }); 
 
      $(".bind").on("click", function() { 
 
       $('.datepicker').datepicker({dateFormat: "yy-mm-dd"}).datepicker("setDate", new Date()).focus(); 
 
      });
<div id="dataRange"> 
 
      <input type="text" name="datein" value=""> 
 
     </div> 
 
     <button class="unbind">unbind</button> 
 
     <button class="bind">bind</button>

+0

有問題在您的代碼段中,無法運行,問題在#17號線 –

+0

請在這裏檢查https://jsfiddle.net/sojitrar88/ymwpon5f/ –

0

拉克什Sojitra是解析器。我只是讓他的代碼爲你剪斷。

$(function() { 
 
       $('#dataRange input').addClass('datepicker'); 
 
       $('.datepicker').datepicker({dateFormat: "yy-mm-dd",autoclose:true}).datepicker("setDate", new Date()).focus(); 
 
       $(".unbind").on("click", function() { 
 
        $('.datepicker').datepicker('destroy'); 
 
       }); 
 
       $(".bind").on("click", function() { 
 
        $('.datepicker').datepicker({dateFormat: "yy-mm-dd"}).datepicker("setDate", new Date()).focus(); 
 
       }); 
 
      });
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/> 
 

 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/locales/bootstrap-datepicker.de.min.js"></script> 
 

 
<form action="#" method="post"> 
 
    <div id="dataRange"> 
 
      <input type="text" name="datein" value=""> 
 
     </div> 
 
     <button class="unbind">unbind</button> 
 
     <button class="bind">bind</button> 
 
</form>