精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
每個程序員都會的 35 個 jQuery 小技巧(3)

21. 驗證元素是否為空

  1. This will allow you to check if an element is empty. 
  2.  
  3. $(document).ready(function() { 
  4.   if ($('#id').html()) { 
  5.    // do something 
  6.    } 
  7. }); 

22. 替換元素

  1. $(document).ready(function() { 
  2.    $('#id').replaceWith(' 
  3. <DIV>I have been replaced</DIV> 
  4.  
  5. '); 
  6. }); 

23. jQuery延時加載功能

  1. $(document).ready(function() { 
  2.    window.setTimeout(function() { 
  3.      // do something 
  4.    }, 1000); 
  5. }); 

24. 移除單詞功能

  1. $(document).ready(function() { 
  2.    var el = $('#id'); 
  3.    el.html(el.html().replace(/word/ig, "")); 
  4. }); 

25. 驗證元素是否存在于jquery對象集合中

  1. $(document).ready(function() { 
  2.    if ($('#id').length) { 
  3.   // do something 
  4.   } 
  5. }); 

26. 使整個DIV可點擊

  1. $(document).ready(function() { 
  2.     $("div").click(function(){ 
  3.       //get the url from href attribute and launch the url 
  4.       window.location=$(this).find("a").attr("href"); return false; 
  5.     }); 
  6. // how to use 
  7. <DIV><A href="index.html">home</A></DIV> 
  8.  
  9. }); 

27. ID與Class之間轉換

當改變Window大小時,在ID與Class之間切換

  1. $(document).ready(function() { 
  2.    function checkWindowSize() { 
  3.     if ( $(window).width() > 1200 ) { 
  4.         $('body').addClass('large'); 
  5.     } 
  6.     else { 
  7.         $('body').removeClass('large'); 
  8.     } 
  9.    } 
  10. $(window).resize(checkWindowSize); 
  11. }); 

28. 克隆對象

  1. $(document).ready(function() { 
  2.    var cloned = $('#id').clone(); 
  3. // how to use 
  4. <DIV id=id></DIV> 
  5.  
  6. }); 

29. 使元素居屏幕中間位置

  1. $(document).ready(function() { 
  2.   jQuery.fn.center = function () { 
  3.       this.css("position","absolute"); 
  4.       this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); 
  5.       this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); 
  6.       return this; 
  7.   } 
  8.   $("#id").center(); 
  9. }); 

30. 寫自己的選擇器

  1. $(document).ready(function() { 
  2.    $.extend($.expr[':'], { 
  3.        moreThen1000px: function(a) { 
  4.            return $(a).width() > 1000; 
  5.       } 
  6.    }); 
  7.   $('.box:moreThen1000px').click(function() { 
  8.       // creating a simple js alert box 
  9.       alert('The element that you have clicked is over 1000 pixels wide'); 
  10.   }); 
  11. }); 

31. 統計元素個數

  1. $(document).ready(function() { 
  2.    $("p").size(); 
  3. }); 

32. 使用自己的 Bullets

  1. $(document).ready(function() { 
  2.    $("ul").addClass("Replaced"); 
  3.    $("ul > li").prepend("? "); 
  4. // how to use 
  5. ul.Replaced { list-style : none; } 
  6. }); 

33. 引用Google主機上的Jquery類庫

  1. //Example 1 
  2. <SCRIPT src="http://www.google.com/jsapi"></SCRIPT> 
  3. <SCRIPT type=text/javascript> 
  4. google.load("jquery", "1.2.6"); 
  5. google.setOnLoadCallback(function() { 
  6.     // do something 
  7. }); 
  8. </SCRIPT><SCRIPT type=text/javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></SCRIPT> 
  9.  
  10. // Example 2:(the best and fastest way) 
  11. <SCRIPT type=text/javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></SCRIPT> 

34. 禁用Jquery(動畫)效果

  1. $(document).ready(function() { 
  2.     jQuery.fx.off = true; 
  3. }); 

35. 與其他Javascript類庫沖突解決方案

  1. $(document).ready(function() { 
  2.    var $jq = jQuery.noConflict(); 
  3.    $jq('#id').show(); 
  4. }); 

【編輯推薦】


本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
14個有用的Jquery技巧分享
jQuery 1.4實用技巧大放送
jquery26個技巧
jquery
Jquery與Prototype混合用法對比
jquery 簡單學習系列
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服

主站蜘蛛池模板: 澜沧| 吴桥县| 泾川县| 平安县| 清水县| 正蓝旗| 滨州市| 银川市| 丰都县| 上虞市| 博湖县| 滨海县| 新和县| 东明县| 武隆县| 崇明县| 龙门县| 无为县| 分宜县| 嘉义县| 清原| 神池县| 邯郸市| 竹北市| 阳原县| 通许县| 安平县| 岑溪市| 东安县| 股票| 东源县| 密云县| 普兰店市| 百色市| 同江市| 巴南区| 商洛市| 平舆县| 化州市| 虹口区| 云梦县|