jQuery Uncaught TypeError : [object Window] 개체의 '$'속성이 함수가 아닙니다.
모두 사전 번들로 제공되는 JS / CSS 양식 응용 프로그램을 다운로드했고 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;
};
});
Wordpress 충돌이 문제를 일으키지 않는다고 가정했기 때문에 마지막 브래킷을 다음과 같이 업데이트했습니다.
}, "jQuery");
그러나 여전히 동일한 오류가 발생합니다. 누구든지이 문제의 원인과 해결 방법을 알고 있습니까?
미리 감사드립니다!
이것은 구문 문제입니다. WordPress에 포함 된 jQuery 라이브러리는 "충돌 없음"모드로로드됩니다. 이는 WordPress에서로드 할 수있는 다른 자바 스크립트 라이브러리와의 호환성 문제를 방지하기위한 것입니다. "no-confict"모드에서는 $ 단축키를 사용할 수 없으며 더 긴 jQuery가 사용됩니다.
jQuery(document).ready(function ($) {
By including the $ in parenthesis after the function call you can then use this shortcut within the code block.
For full details see WordPress Codex
My favorite no-conflict-friendly construct:
jQuery(function($) {
// ...
});
Calling jQuery with a function pointer is a shortcut for $(document).ready(...)
Or as we say in coffeescript:
jQuery ($) ->
# code here
In Wordpress just replace
$(function(){...});
with
jQuery(function(){...});
You can consider to replace default WordPress jQuery script with Google Library by adding something like the following into theme functions.php file:
function modify_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false, '1.10.2');
wp_enqueue_script('jquery');
}
}
add_action('init', 'modify_jquery');
Code taken from here: http://www.wpbeginner.com/wp-themes/replace-default-wordpress-jquery-script-with-google-library/
maybe you have code like this before the jquery:
var $jq=jQuery.noConflict();
$jq('ul.menu').lavaLamp({
fx: "backout",
speed: 700
});
and them was Conflict
you can change $ to (jQuery)
'developer tip' 카테고리의 다른 글
Eclipse에서 기본 작업 공간을 요청하도록 강제하는 방법은 무엇입니까? (0) | 2020.09.02 |
---|---|
JSON의 작은 따옴표와 큰 따옴표 (0) | 2020.09.02 |
데이터베이스 스키마가 있는지 쿼리하는 방법 (0) | 2020.09.02 |
열의 값으로 데이터 프레임 필터링 (0) | 2020.09.02 |
MongoDB를 처음 사용하는 경우 mongo 명령을 실행할 수 없습니다. (0) | 2020.09.02 |