JS / jQuery TypeError:jQuery(...)。datepicker不是一个函数 [英] JS/jQuery TypeError: jQuery(...).datepicker is not a function

查看:101
本文介绍了JS / jQuery TypeError:jQuery(...)。datepicker不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在抓住我的头2天,很确定我只是想念一些简单的东西,但是我不知道为什么它不起作用。

I've been scratching my head on this for 2 days, pretty sure I'm just missing something simple but I can't for the life of me figure out why it's not working.

我试图在我的WordPress网站上使用下面的脚本来禁用ContactForm7表单中的datepicker字段中的特定日期。

I'm trying to use the script below on my WordPress site to disable specific dates within a datepicker field in a ContactForm7 form.

我可以在jsfiddle中使用一个简单的输入字段使用相同的id加载脚本,它的工作原理完美...但是当我将它添加到我的网站时,日期不会被禁用,JS错误控制台中有一个错误,说jQuery ...)。datepicker不是一个函数

I can load the script in jsfiddle with a simple input field using the same id and it works perfectly...but when I add it to my site the dates aren't disabled, and there's an error in the JS error console that says "jQuery(...).datepicker is not a function"

我已经添加到我的 header.php 文件,刚刚低于 wp_head()调用,并刚刚在< / head> 标签之上。我分配了我的datepicker字段,其ID为 dpick ,如脚本所使用。

I've added it in my header.php file, just below the wp_head() call and just above the </head> tag. I've assigned my datepicker field with the id of dpick like the script uses.

我读到这个错误通常在使用 $ 符号时引起,因为它可能与WordPress中的其他jQuery脚本冲突...所以他们建议替换 $ jQuery (我在下面的脚本中完成)...但我仍然收到错误

I read that this error is commonly caused when using the $ symbol because it can conflict with other jQuery scripts within WordPress...so they suggested replacing $ with jQuery instead (which I've done in the script below)...but I'm still getting the error

var unavailableDates = ["1-9-2013", "2-9-2013", "3-9-2013", "4-9-2013", "5-9-2013"];

    function unavailable(date) {
            dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
            if (jQuery.inArray(dmy, unavailableDates) == -1) {
                return [true, ""];
            } else {
                return [false, "", "Unavailable"];
        }
    }

        jQuery(function() {
            jQuery( '#dpick' ).datepicker({
                dateFormat: 'dd MM yy',
                beforeShowDay: unavailable
        });

    });

不能感谢你足够的帮助,你可以提供...这似乎像这样简单事情,但我似乎不能包围我的头!

Can't thank you enough for any help you can offer...this seems like such a simple thing but I just can't seem to wrap my head around it!

推荐答案

这是错误的几个原因: p>

The are several reasons for this error:


  1. jquery.ui在jquery之前使用。

  2. $由另一个库使用。 li>
  3. 本地引用的jquery库(wordpress)与使用jquery.ui的版本不同。

  4. 当引用正确的库和版本时,浏览器必须清除缓存。

这篇关于JS / jQuery TypeError:jQuery(...)。datepicker不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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