一级毛片视频在线观看-一级毛片视频免费-一级毛片视频播放-一级毛片看真人在线视频-国产高清在线精品一区a-国产高清在线精品一区二区

程序猿都要了解的35個 jQuery 小技巧(下)

作者:網站建設公司 來源:佛山網站建設日期:2020-11-11 瀏覽:

網站建設 - 建站教程 - 網頁設計 - 程序猿都要了解的35個 jQuery 小技巧(下)

收集的35個 jQuery 小技巧/代碼片段,可以幫你快速開發.


17.阻止鏈接加載


有時你不希望鏈接到某個頁面或者重新加載它,你可能希望它來做一些其他事情或者觸發一些其他腳本,你可以這么做:

$('a.no-link').click(function (e) {
  e.preventDefault();
});
18.切換 fade/slide

fade 和 slide 是我們在 jQuery 中經常使用的動畫效果,它們可以使元素顯示效果更好。但是如果你希望元素顯示時使用種效果,而消失時使用第二種效果,則可以這么做:

// Fade
$('.btn').click(function () {
  $('.element').fadeToggle('slow');
});
// Toggle
$('.btn').click(function () {
  $('.element').slideToggle('slow');
});
19.簡單的手風琴效果

這是一個實現手風琴效果快速簡單的方法:

// Close all panels
$('#accordion').find('.content').hide();
// Accordion
$('#accordion').find('.accordion-header').click(function () {
  var next = $(this).next();
  next.slideToggle('fast');
  $('.content').not(next).slideUp('fast');  return false;
});
20.讓兩個 DIV 高度相同

有時你需要讓兩個 div 高度相同,而不管它們里面的內容多少??梢允褂孟旅娴拇a片段:

var $columns = $('.column');var height = 0;
$columns.each(function () {
  if ($(this).height() > height) {
    height = $(this).height();
  }
});
$columns.height(height);
這段代碼會循環一組元素,并設置它們的高度為元素中的大高。
21. 驗證元素是否為空

This will allow you to check if an element is empty.

$(document).ready(function() {
  if ($('#id').html()) {
     // do something
   }
});
22. 替換元素

Want to replace a div, or something else?

$(document).ready(function() {
   $('#id').replaceWith('
<DIV>I have been replaced</DIV>

');
});
23. jQuery延時加載功能

Want to delay something?

$(document).ready(function() {
   window.setTimeout(function() {
        // do something
   }, 1000);
});
24. 移除單詞功能

Want to remove a certain word(s)?

$(document).ready(function() {
   var el = $('#id');
   el.html(el.html().replace(/word/ig, ""));
});
25. 驗證元素是否存在于jquery對象集合中

Simply test with the .length property if the element exists.

$(document).ready(function() {
   if ($('#id').length) {
     // do something
  }
});
26. 使整個DIV可點擊

Want to make the complete div clickable?

$(document).ready(function() {
    $("div").click(function(){
          //get the url from href attribute and launch the url
      window.location=$(this).find("a").attr("href"); return false;
    });// how to use<DIV><A href="index.html">home</A></DIV>});
27. ID與Class之間轉換

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

$(document).ready(function() {
   function checkWindowSize() {
       if ( $(window).width() > 1200 ) {
        $('body').addClass('large');
    }    else {
        $('body').removeClass('large');
    }
   }
$(window).resize(checkWindowSize);
});
28. 克隆對象

Clone a div or an other element.

$(document).ready(function() {
   var cloned = $('#id').clone();// how to use<DIV id=id></DIV>});
29. 使元素居屏幕中間位置

Center an element in the center of your screen.

$(document).ready(function() {
  jQuery.fn.center = function () {
        this.css("position","absolute");
              this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
                    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
                          return this;
  }
  $("#id").center();
});
30. 寫自己的選擇器

Write your own selectors.

$(document).ready(function() {
   $.extend($.expr[':'], {
       moreThen1000px: function(a) {
                  return $(a).width() > 1000;
      }
   });
  $('.box:moreThen1000px').click(function() {
        // creating a simple js alert box
      alert('The element that you have clicked is over 1000 pixels wide');
  });
});
31. 統計元素個數

Count an element.

$(document).ready(function() {
   $("p").size();
});
32. 使用自己的 Bullets

Want to use your own bullets instead of using the standard or images bullets?

$(document).ready(function() {
   $("ul").addClass("Replaced");
   $("ul > li").prepend("? "); // how to use
 ul.Replaced { list-style : none; }
});
33. 引用Google主機上的Jquery類庫

Let Google host the jQuery script for you. This can be done in 2 ways.

//Example 1
<SCRIPT src="http://www.86807888.com.cn/uploads/szweb/http://www.google.com/jsapi"></SCRIPT>
<SCRIPT type=text/javascript>
google.load("jquery", "1.2.6");
google.setOnLoadCallback(function() {
    // do something
});
</SCRIPT><SCRIPT type=text/javascript src="http://www.86807888.com.cn/uploads/szweb/http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></SCRIPT>
 // Example 2:(the best and fastest way)
<SCRIPT type=text/javascript src="http://www.86807888.com.cn/uploads/szweb/http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></SCRIPT>
34. 禁用Jquery(動畫)效果

Disable all jQuery effects

$(document).ready(function() {
    jQuery.fx.off = true;
});
35. 與其他Javascript類庫沖突解決方案

To avoid conflict other libraries on your website, you can use this jQuery Method, and assign a different variable name instead of the dollar sign.

$(document).ready(function() {
   var $jq = jQuery.noConflict();
   $jq('#id').show();

});


程序猿都要了解的35個 jQuery 小技巧(上)


企業網站建設一條龍
找零度飛易網絡公司-fslingdu所做php網站建設方案、網站設計、網站制作北京上海深圳龍崗衢州蘭州常州東營南通濟寧桂林淮安煙臺長春無錫天津昆山蘇州合肥洛陽昆明天津唐山泉州惠州萬州新鄉商丘臺州哈爾濱太原攝影???/strong>隨州學校商丘廣東湖南廣西江西海南廣州企業中小企業武漢南山羅湖福田虎門肇慶汕尾汕頭廣州佛山成都杭州濟南重慶福州西安廈門昆山沈陽青島徐州鄭州南京南寧長沙大連淄博石家莊南昌溫州珠海番禺順德三水高明中山東莞合肥江門嘉興西寧大良容桂倫教勒流陳村均安杏壇龍江樂從北滘祖廟石灣南莊等地區企業網站建設(廣告)公司提供專業做網站價格規劃書及營銷型網站制作,網站建設基礎知識

網站建設費用

網站制作電話:137 1543 1176

網站開發QQ:378780108

E-mailsale@fslingdu.com如何制作網站QQ :378780108

網站建設服務

網站建設公司零度飛易是一家專業網站設計,網站制作、seo優化,網站推廣,網站建設的佛山網絡運營公司。零度飛易在家具網站建設、小家電網站建設服裝網站建設、電器網站建設、機械網站建設等行業的網站設計、網絡運營都得到行業認可,在上海、深圳、北京廣州、佛山中山、東莞地區有著良好的口碑品牌的網站建設公司。我們的使命是打造創新型的網站建設企業,能輕易地開展“互聯網+”業務、實現“互聯網+企業”的企業愿景。

Hi,Are you ready?

準備好開始了嗎?
那就與我們取得聯系吧

有一個互聯網項目想和我們談談嗎?您可以填寫右邊的表格,讓我們了解您的項目需求,這是一個良好的開始,我們將會盡快與你取得聯系。當然也歡迎您給我們寫信或是打電話,讓我們聽到你的聲音!

零度飛易 互聯網整合營銷

地址:佛山市順德區大良鳳翔商業廣場二座670

業務QQ:378780108

策劃專線:13715431176

E-mail:sale@fslingdu.com

合作意向表

您需要的服務

現有網站改版
我需要做微信營銷
建設全新的企業網站
要找長期合作公司,需要年度服務
我需要做購物商城
我需要做系統平臺

您最關注的地方

對功能要求比較高
對設計創意要求比較高
需要可以購物支付
搜索引擎排名

價格預算

1-3萬3-5萬5-8萬8-10萬10萬以上大型項目需要招標