튜토리얼 here에서 jquery에 웹 위젯을 작성합니다.잡히지 않은 TypeError : 객체 [object Object]의 'jQuery'속성이 함수가 아닙니다.
기본적으로 jQuery가로드되었는지 확인하고 그렇지 않으면로드합니다. 내 위젯은 버튼 하나만 표시하고 onClick은 iframe을로드하는 fancybox를 보여줍니다.
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function() { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else { // Other browsers
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function($) {
// We can use jQuery 1.4.2 here
/**** LOAD FANCYBOX ******/
$.getScript("fancyboxURL");
// I also tried loading fancybox here but that didnt work either
$(".fancybox").fancybox();
});
}
})(); // We call our anonymous function immediately
페이지를로드 할 때 아래 오류가 발생합니다.
Uncaught TypeError: undefined is not a function jquery.fancybox.pack.js?v=2.1.5:2
Uncaught TypeError: Cannot read property 'fancybox' of undefined jquery.fancybox-thumbs.js?v=1.0.7:19
Uncaught TypeError: Property '$' of object [object Object] is not a function
일부 시도 오류 Property "$" ....
오류에서 오는 파일에서
, 그것은 현재 내가
으로 시도해야 것으로 나타났습니다 다른 스레드에서$(document).ready(function(){
$(".fancybox").fancybox();
});
를 읽고
jQuery(function($){
$(".fancybox").fancybox();
});
하지만 t는 단지 Property "jQuery" of object is not a function
을주었습니다.
내가 수동으로 jQuery
을 내 html 파일에 포함하면 코드가 제대로 작동한다는 것을 알고 있습니다. 아래
내 HTML 파일 : -
<html>
<head>
<!-- IF I UNCOMMENT THE BELOW LINE IT WORKS! Add jQuery library -->
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> </script>-->
</head>
<body>
<!-- load widget -->
<script src="http://mywidgetURL.../widget/myWidget.js" type="text/javascript"></script>
<div id="widget-container"></div>
</body>
</html>
내가 크롬에 요소를 검사 할 때 발생하는 마크 업 jQuery를로드되었음을 나타냅니다 보인다.
그런 짓을. – ethree
하지만 jQuery 라이브러리는 위젯 javascript에 포함되어야합니다. 자, 제 질문을 편집하여 자바 스크립트를 보여 주도록하겠습니다. – chongzixin
jQuery를 포함 할 때 ...'$ (document) .ready (..)'코드가 실행될 때 ... jQuery가로드되지 않았을 가능성이 있습니다 .... –