我对jQuery并不陌生,而且我在Bootstrap Datepicker方面有很多经验并且从未遇到过问题。但是,这个项目有很多jQuery UI Datepicker的遗留配置,这些配置或多或少地限制了我使用它。不管出于何种原因,我似乎无法初始化它。我正在使用CDN中的jQuery和jQuery UI,而我并没有尝试做任何想象的事情。
以下是一切在最基本状态下的设置。
CDN:
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
初始化:
<script type="text/javascript">
$("#checkin").datepicker();
</script>
HTML:
<div class="travel-dates small">
<div class="date">
<label for="checkin">Check in</label>
<div class="input-group form-group">
<input name='checkin' id="checkin" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
<div class="date">
<label for="checkout">Check out</label>
<div class="input-group form-group">
<input name="checkout" id="checkout" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
</div>
我尝试使用$(&#34;#checkin&#34;)。datepicker(&#34; show&#34;)在点击时调用datepicker,当我这样做时,我收到错误&#34 ; t未定义,&#34;它在跟踪中引用了datepicker。
我一定是在遗漏某些东西,或者做错了什么,但我无法让这一切为我的生活而努力。我已经浏览了关于该主题的所有其他SO答案,并且没有找到任何有用的答案。老实说,在决定使用其他东西重做他们为jQuery UI Datepicker做的所有很酷的事情时更容易,而不是试图让这个很好地继续工作错误。任何帮助或建议将不胜感激。
更新
我上面发布的内容在我将其复制回来时最终工作了。我正在处理的网站是一个已经移植到PHP的角度站点,我的输入仍然有一些角度类。这些类没有在我们当前的CSS文件中定义,我们还没有去除它们。出于某种原因,删除这些类就可以了。为了澄清,日历没有被隐藏或显示:无,它无法初始化而没有错误。现在一切都在运转,但如果有人能解开为什么额外的未定义类导致它失败的话,我会很好奇。
原始HTML:
<div class="travel-dates small ng-isolate-scope">
<div class="date">
<label for="checkin" class="ng-scope">Check in</label>
<div class="input-group form-group">
<input name='checkin' id="checkin" class="form-control input-sm ng-pristine ng-invalid ng-invalid-required hasDatepicker" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
<div class="date">
<label for="checkout" class="ng-scope">Check out</label>
<div class="input-group form-group">
<input name="checkout" id="checkout" class="form-control input-sm ng-pristine ng-invalid ng-invalid-required hasDatepicker" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm" disabled="disabled"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
</div>
答案 0 :(得分:1)
我无法像你描述的那样复制你的问题。我怀疑加载jQuery UI时会出现问题。
$(function() {
$("#checkin").datepicker();
});
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<div class="travel-dates small">
<div class="date">
<label for="checkin">Check in</label>
<div class="input-group form-group">
<input name='checkin' id="checkin" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
<div class="date">
<label for="checkout">Check out</label>
<div class="input-group form-group">
<input name="checkout" id="checkout" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
<span class="input-group-btn">
<button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
</div>
</div>