鋒利的jquery之快速定位

來源:互聯網
上載者:User


ul,li{margin:0px;padding:0px;list-style:none;}


.Loading{width:400px;/*margin-left:auto;//margin-right:auto;*/margin:0 auto;visibility:hidden;}


#contentsecond{width:300px;height:100px;}




$("#realcontent").load("test.html");

$("div.contentin").removeClass("contentin");



function setBorder( n ){    } 

(function() { var // Will speed up references to window, and allows munging its name. window = this, // Will speed up references to undefined, and allows munging its name. undefined, // Map over jQuery in case of overwrite _jQuery = .jQuery, // Map over the $ in case of overwrite _$ = window.$, jQuery = window.jQuery = window.$ = function(selector, context) { // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init(selector, context); }, // A simple way to check for HTML strings or ID strings // (both of which we optimize for) quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/, // Is it a simple selector isSimple = /^.[^:#\[\.,]*$/; jQuery.fn = jQuery.prototype = { init: function(selector, context) { // Make sure that a selection was provided // Make sure that a selection was provided selector = selector || document; this[0] = selector; this.length = 1; this.context = selector; return this; }, show:function() { alert("this.show"); }, // Start with an empty selector selector: "", // The current version of jQuery being used jquery: "1.3.2" }; jQuery.fn.init.prototype = jQuery.fn; })(); function test(src){ alert($(src)); $(src).show();

    像這樣的就是隱式迭代因為$(".yourclass")選到的元素不一定只有一個,比如$(".yourclass")選中n個元素  這n個元素都會加上"newclas"這個class,除了ID選取器其它都是隱式迭代的比如$("#yourclass") 就算有多個id="yourclass" 也只能得到第1個在jqery中,因為它迭代的時候只取第一個元素!所有的方法都被設計成自動操作對象集合,而不是單一的一個對象,這樣避免了大量的沒有意義的迴圈

    1,要向寫好代碼,必須不斷最佳化改進!
    2,要向做好軟體,盡量靈活抽象是正道
    3,一個團隊的管理,猶如設計一個頁面,快速定位某項工作的基礎是有一個全域的管理觀念(參考代碼中的window)


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.