jQuery Uncaught TypeError:對象[對象窗口]的屬性'$'不是函數(shù)全部,我下載了一個預(yù)先綁定的JS / CSS表單應(yīng)用程序,我正在嘗試在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();
});
});我假設(shè)Wordpress沒有沖突導(dǎo)致問題,所以我更新了最后一個括號,如下所示:}, "jQuery");但是,我仍然遇到同樣的錯誤。有誰知道會出現(xiàn)什么問題以及如何解決這個問題?提前致謝!
3 回答

慕蓋茨4494581
TA貢獻1850條經(jīng)驗 獲得超11個贊
這是一個語法問題,WordPress附帶的jQuery庫以“無沖突”模式加載。這是為了防止WordPress可以加載的其他JavaScript庫的兼容性問題。在“無混淆”模式下,$快捷方式不可用,并且使用了更長的jQuery,即
jQuery(document).ready(function ($) {
通過在函數(shù)調(diào)用后包含$ in括號,您可以在代碼塊中使用此快捷方式。
有關(guān)詳細信息,請參閱WordPress Codex

德瑪西亞99
TA貢獻1770條經(jīng)驗 獲得超3個贊
我最喜歡的不沖突友好的構(gòu)造:
jQuery(function($) { // ... });
使用函數(shù)指針調(diào)用jQuery是$(document).ready(...)的快捷方式
或者正如我們在coffeescript中所說:
jQuery ($) -> # code here
- 3 回答
- 0 關(guān)注
- 405 瀏覽
添加回答
舉報
0/150
提交
取消