全, 我下载了一个预先Bundle 的JS/CSS表单应用程序,我正try 在Wordpress中使用它.我有以下代码:

$(document).ready(function () {


/*----------------------------------------------------------------------*/
/* Parse the data from an data-attribute of DOM Elements
/*----------------------------------------------------------------------*/


$.parseData = function (data, returnArray) {
    if (/^\[(.*)\]$/.test(data)) { //array
        data = data.substr(1, data.length - 2).split(',');
    }
    if (returnArray && !$.isArray(data) && data != null) {
        data = Array(data);
    }
    return data;
};

/*----------------------------------------------------------------------*/
/* Image Preloader
/* http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
/*----------------------------------------------------------------------*/



// Arguments are image paths relative to the current page.
$.preload = function() {
    var cache = [],
        args_len = arguments.length;
    for (var i = args_len; i--;) {
        var cacheImage = document.createElement('img');
        cacheImage.src = arguments[i];
        cache.push(cacheImage);
    }
};


/*----------------------------------------------------------------------*/
/* fadeInSlide by revaxarts.com
/* Fades out a box and slide it up before it will get removed
/*----------------------------------------------------------------------*/


$.fn.fadeInSlide = function (speed, callback) {
    if ($.isFunction(speed)) callback = speed;
    if (!speed) speed = 200;
    if (!callback) callback = function () {};
    this.each(function () {

        var $this = $(this);
        $this.fadeTo(speed / 2, 1).slideDown(speed / 2, function () {
            callback();
        });
    });
    return this;
};


/*----------------------------------------------------------------------*/
/* fadeOutSlide by revaxarts.com
/* Fades out a box and slide it up before it will get removed
/*----------------------------------------------------------------------*/


$.fn.fadeOutSlide = function (speed, callback) {
    if ($.isFunction(speed)) callback = speed;
    if (!speed) speed = 200;
    if (!callback) callback = function () {};
    this.each(function () {

        var $this = $(this);
        $this.fadeTo(speed / 2, 0).slideUp(speed / 2, function () {
            $this.remove();
            callback();
        });
    });
    return this;
};

/*----------------------------------------------------------------------*/
/* textFadeOut by revaxarts.com
/* Fades out a box and slide it up before it will get removed
/*----------------------------------------------------------------------*/


$.fn.textFadeOut = function (text, delay, callback) {
    if (!text) return false;
    if ($.isFunction(delay)) callback = delay;
    if (!delay) delay = 2000;
    if (!callback) callback = function () {};
    this.each(function () {

        var $this = $(this);
        $this.stop().text(text).show().delay(delay).fadeOut(1000,function(){
            $this.text('').show();
            callback();
        })
    });
    return this;
};

/*----------------------------------------------------------------------*/
/* leadingZero by revaxarts.com
/* adds a leding zero if necessary
/*----------------------------------------------------------------------*/


$.leadingZero = function (value) {
    value = parseInt(value, 10);
    if(!isNaN(value)) {
        (value < 10) ? value = '0' + value : value;
    }
    return value;
};


});

I was assuming that the Wordpress no conflict was causing an issue so I updated the very last bracket to look like the following:

}, "jQuery");

但是,我仍然收到相同的错误.有没有人知道这个问题会引发什么,以及如何解决它?

提前谢谢!

推荐答案

这是一个语法问题,WordPress附带的jQuery库以"无冲突"模式加载.这是为了防止与WordPress可以加载的其他javascript库的兼容性问题.在"无混淆"模式下,$快捷方式不可用,并且使用的jQuery时间越长,即

jQuery(document).ready(function ($) {

通过在函数调用后的圆括号中包含$,您就可以在代码挡路中使用此快捷方式.

For full details see WordPress Codex

Jquery相关问答推荐

逐个交换图像

formData.append 来自不同输入文件的两个文件

javascript 捕获浏览器快捷方式 (ctrl+t/n/w)

缺少 .map 资源?

使用淡入淡出和追加

如何在循环内创建动态变量名称?

JSON 服务在失败/错误时应该返回什么

javascript中的描述关键字

Jquery查找所有以字符串开头的ID?

jQuery 对象和 DOM 元素

如何在 JQuery DataTable 中默认显示所有行

jquery获取帖子操作网址

使用 D3.js(IE、safari 和 chrome)创建 SVG 后,如何保存/导出 SVG 文件?

使用 jQuery 获取选定的选项 id

jQuery:获取父母,父母ID?

测试两个元素是否相同

CORS POST 请求可以使用纯 JavaScript,但为什么不使用 jQuery?

jquery分别绑定双击和单击

什么时候应该使用 jQuery 的 document.ready 函数?

IE 中带有 jQ​​uery ajax 调用的无传输错误