Javascript를 사용하여 jquery 가로 드되었는지 확인
내 Jquery 라이브러리가 HTML 페이지에로드되어 있는지 확인하려고합니다. 작동하는지 확인하고 있지만 뭔가 잘못되었습니다. 여기 내가 가진 것입니다 :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/query-1.6.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if (jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
});
</script>
뭔가 옳지 않다
글쎄, jQuery를 사용하여 jQuery가 있는지 확인합니다. jQuery 가로 드 $()되지 않으면 다른 라이브러리를 사용하지 않고 해당 라이브러리가 동일한 $()구문 을 공유하지 않는 한 전혀 실행되지 않으며 콜백이 실행되지 않습니다 .
제거하십시오 $(document).ready()( window.onload대신 비슷한 것을 사용 하십시오 ).
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
}
당 이 링크 :
if (typeof jQuery == 'undefined') {
// jQuery IS NOT loaded, do stuff here.
}
링크에 대한 의견에는 몇 가지가 더 있습니다.
if (typeof jQuery == 'function') {...}
//or
if (typeof $== 'function') {...}
// or
if (jQuery) {
alert("jquery is loaded");
} else {
alert("Not loaded");
}
이것이이 일을 끝내는 가장 좋은 방법을 다루기를 바랍니다.
if ('undefined' == typeof window.jQuery) {
// jQuery not present
} else {
// jQuery present
}
웹 페이지를 검사 할 때 콘솔 탭에서이를 빠르게 수행 할 수 있습니다.
예 :
$ === jQuery
If it returns true it means it's loaded.
Just a small modification that might actually solve the problem:
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
location.reload();
}
}
Instead of $(document).Ready(function() use window.onload = function().
You can just type window.jQuery in Console . If it return a function(e,n) ... Then it is confirmed that the jquery is loaded and working successfully.
A quick way is to run a jQuery command in the developer console. On any browser hit F12 and try to access any of the element .
$("#sideTab2").css("background-color", "yellow");
참고URL : https://stackoverflow.com/questions/7341865/checking-if-jquery-is-loaded-using-javascript
'IT' 카테고리의 다른 글
| 문자열 바로 JavaScript를 자릅니다 (0) | 2020.06.12 |
|---|---|
| VSCode에서 선택한 단어를 모두 선택하십시오. (0) | 2020.06.12 |
| 명령 줄을 사용하여 JSON 객체의 항목을 계산하는 방법은 무엇입니까? (0) | 2020.06.12 |
| 바이트 배열을 기본 null 이외의 특정 값으로 초기화 하시겠습니까? (0) | 2020.06.12 |
| 부울 검사에 xor 연산자를 사용하는 것이 좋습니다? (0) | 2020.06.12 |
