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

查看:26
本文介绍了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 表单中日期选择器字段中的特定日期.

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

我可以使用相同的 id 使用简单的输入字段在 jsfiddle 中加载脚本,它运行良好……但是当我将它添加到我的网站时,日期没有被禁用,并且 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 字段分配了 dpick 的 ID,就像脚本使用的一样.

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!

推荐答案

导致此错误的几个原因:

The are several reasons for this error:

  1. jquery.ui 在 jquery 之前使用.
  2. $ 被另一个库使用.
  3. 本地引用的 jquery 库 (wordpress) 与使用 jquery.ui 的版本不同.
  4. 当引用正确的库和版本时,必须清除浏览器缓存.

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

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