Utilities - $ 기호 사용금지 : 다른 라이브러리와 함께 사용
.NET프로그래밍/jQuery 1.3.2 2009. 11. 17. 10:07 |
$.noConflict()
• $.noConflict()
– 다른 라이브러리와 jQuery 사용시
• $대신 jQuery키워드 사용해야 함.
• 다른 라이브러리에게 $를 양보
------------------------------------------------------------------------------------
[NoConflict.htm]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$ 기호 사용금지 : 다른 라이브러리와 함께 사용</title>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
// 현재 페이지에서는 $대신에 jQuery를 사용
// 다른 자바스크립트 라이브러리가 $를 사용하기에 양보
$.noConflict();
// var $ = "메롱~"; // $를 재정의
// jQuery(document).ready(function() {
// alert($); // undefined (정의되지 않은) -> 메롱~
// });
// 지금까지 만들어 놓은 기능은 $로 되있다면?
jQuery(document).ready(function($) { // function에 매개변수로 $ 넣어줌
// 여기에 있는 코드들은 기존 방식처럼 $를 쓰고 싶다면?
alert($);
$('#my').append("<h3>기존방식 사용</h3>");
jQuery('#my').append("<h3>기존방식 사용</h3>");
});
</script>
</head>
<body>
<div id="my"></div>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
jQuery UI 다운로드 및 설치 그리고 활용 (0) | 2009.11.17 |
---|---|
Utilities - 문자열 매개변수를 쿼리스트링으로 변경 (0) | 2009.11.17 |
Utilities - 양쪽 공백 제거 함수 : trim() (0) | 2009.11.17 |
Utilities - 브라우저 정보 얻기 (0) | 2009.11.17 |
반복사용하는 ajax() 메서드의 주요 속성을 ajaxSetup()에서 설정 (0) | 2009.11.17 |