【问题标题】:Unable to remove bootstrap date picker from textbox无法从文本框中删除引导日期选择器
【发布时间】:2016-09-30 05:37:14
【问题描述】:

我的情况是我有几个文本框 我在 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');

然后我不能用第一个代码改回日期选择器,日期选择器下拉框不显示:(

【问题讨论】:

  • 只删除类还不够吗?
  • @madalinivascu nope
  • i manually add bootstrap datetime picker .. 但我只看到datepicker
  • @Novice 更新了我的问题 :) 谢谢

标签: jquery datepicker bind bootstrap-datepicker unbind


【解决方案1】:

它在这里工作请看这个。我认为你错过了一些事件。我添加了 两个按钮,例如 bind 和 unbind,在点击事件中我分别绑定和取消绑定 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>

【讨论】:

  • 您的 sn-p 有问题,无法运行,在第 17 行发出问题
【解决方案2】:

Rakesh 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多