检查Bootstrap Datepicker脚本是否已加载 [英] Check if Bootstrap Datepicker script has loaded

查看:117
本文介绍了检查Bootstrap Datepicker脚本是否已加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:

 未捕获的TypeError:undefined不是函数
  $( '日期选择器')日期选择器(); 

如何确定datepicker是否已加载?



要清楚,我没有使用jQuery UI ($ .fn.datepicker){
/ b

 可以检查datepicker脚本是否已经使用: / ... 
}

然后,您可以有条件地调用 .datepicker()方法如果脚本已经加载: {
$('。datepicker')。datepicker();
}

此处示例



这样做,如果脚本尚未加载,则不会引发错误。




您也可以使用:

  if(typeof $()。datepicker ==='function'){
$('。datepicker')。datepicker();
}

此处示例


I am receiving the error:

Uncaught TypeError: undefined is not a function

When I try to set up the datepicker:

$('.datepicker').datepicker();

How can I determine if the datepicker has loaded or not?

To be clear, I'm not using jQuery UI

解决方案

You can check to see if the datepicker script has loaded using:

if ($.fn.datepicker) {
    // ...
}

Then you can conditionally invoke the .datepicker() method if the script has loaded:

if ($.fn.datepicker) {
    $('.datepicker').datepicker();
}

Example Here

In doing so, the error won't be thrown if the script hasn't loaded.


You can also use:

if (typeof $().datepicker === 'function') {
    $('.datepicker').datepicker();
}

Example Here

这篇关于检查Bootstrap Datepicker脚本是否已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆