- 註冊時間
- 2013-4-16
- 最後登錄
- 2023-7-6
- 閱讀權限
- 100
- 積分
- 26424
- 精華
- 0
- 帖子
- 8169
|
Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.
就像jQuery一樣,許多JavaScript庫都將$用作函數或變量名。 在jQuery的情況下,$只是jQuery的別名,因此無需使用$即可使用所有功能。 如果您需要在jQuery旁邊使用另一個JavaScript庫,請通過調用$ .noConflict()將$的控制權返回到另一個庫。 $的舊引用在jQuery初始化期間保存; noConflict()只是還原它們。- <script src="other_lib.js"></script>
- <script src="jquery.js"></script>
- <script>
- $.noConflict();
- // Code that uses other library's $ can follow here.
- </script>
複製代碼- <script src="other_lib.js"></script>
- <script src="jquery.js"></script>
- <script>
- $.noConflict();
- jQuery( document ).ready(function( $ ) {
- // Code that uses jQuery's $ can follow here.
- });
- // Code that uses other library's $ can follow here.
- </script>
複製代碼- jQuery.noConflict();
- // Do something with jQuery
- jQuery( "div p" ).hide();
- // Do something with another library's $()
- $( "content" ).style.display = "none";
複製代碼- jQuery.noConflict();
- (function( $ ) {
- $(function() {
- // More code using $ as alias to jQuery
- });
- })(jQuery);
複製代碼 |
|