object(mysqli_result)#13 (5) { ["current_field"]=> int(0) ["field_count"]=> int(25) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) } jQuery.noConflict() - 程序員論壇 - Powered by Discuz!

程序員論壇

標題: jQuery.noConflict() [打印本頁]

作者: GreenCup    時間: 2020-2-27 11:42
標題: jQuery.noConflict()
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()只是還原它們。
  1. <script src="other_lib.js"></script>
  2. <script src="jquery.js"></script>
  3. <script>
  4. $.noConflict();
  5. // Code that uses other library's $ can follow here.
  6. </script>
複製代碼
  1. <script src="other_lib.js"></script>
  2. <script src="jquery.js"></script>
  3. <script>
  4. $.noConflict();
  5. jQuery( document ).ready(function( $ ) {
  6.   // Code that uses jQuery's $ can follow here.
  7. });
  8. // Code that uses other library's $ can follow here.
  9. </script>
複製代碼
  1. jQuery.noConflict();
  2. // Do something with jQuery
  3. jQuery( "div p" ).hide();
  4. // Do something with another library's $()
  5. $( "content" ).style.display = "none";
複製代碼
  1. jQuery.noConflict();
  2. (function( $ ) {
  3.   $(function() {
  4.     // More code using $ as alias to jQuery
  5.   });
  6. })(jQuery);
複製代碼





歡迎光臨 程序員論壇 (http://program.thesmartfire.com/) Powered by Discuz! X2.5