jimingminlovefly

          統(tǒng)計(jì)

          最新評論

          jquery常用方法

          1.jQuery(expression, [context])

          默認(rèn)情況下, 如果沒有指定context參數(shù),$()將在當(dāng)前的 HTML document中查找 DOM 元素;如果指定了 context 參數(shù),如一個(gè) DOM 元素集或 jQuery 對象,那就會(huì)在這個(gè) context 中查找。
          例如:
          獲取父窗口的元素方法:$(selector, window.parent.document);

          在文檔的第一個(gè)表單中,查找所有的單選按鈕(即: type 值為 radio 的 input 元素):$("input:radio", document.forms[0]);

          2. 編寫一個(gè)簡單的 jQuery 插件(模板)


          //You need an anonymous function to wrap around your function to avoid conflict
          (function($){
            
          //method一:
              //Attach this new method to jQuery
              $.fn.extend({
                    
                  //This is where you write your plugin's name
                  pluginname: function() {
            
                      //options
                //      var defaults = {
                //          option1: "default_value"
                //      }
                       
               //       var options = $.extend(defaults, options);
            
                      //a public method
               //       this.methodName: function () {
                          //call this method via $.pluginname().methodName();
                //      }
            
                      //Iterate over the current set of matched elements
                      return this.each(function() {
                        
                //          var o = options;
                        
                          //code to be inserted here
                        
                      });
                  }
              });
                
          //pass jQuery to the function,
          //So that we will able to use any valid Javascript variable name
          //to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )   
          //method二:  
          $.fn.pluginname=function(){
           return this.each(function() { });
           
          }
           
          })(jQuery);

          實(shí)例:

           <script type="text/javascript">
          (function($){
           
          $.fn.extend({
            check: function() {
              return this.each(function() { alert(0); });
            },
            uncheck: function() {
              return this.each(function() { alert(1); });
            }
          });

          $.fn.suggest=function(){
              return this.each(function() { alert(2); }); 
          }

          })(jQuery);

          function check(){
           if($("input").attr("checked")){
           $("input").check();
           }else{
           $("input").uncheck();
           }
           $("input").suggest();
          }
            </script>


          posted on 2012-06-27 20:10 計(jì)明敏 閱讀(226) 評論(0)  編輯  收藏 所屬分類: jquery


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 武功县| 筠连县| 册亨县| 延边| 堆龙德庆县| 洞头县| 手游| 东安县| 饶阳县| 南平市| 昌都县| 涞水县| 密山市| 台前县| 伊金霍洛旗| 莲花县| 邹平县| 新安县| 商城县| 云林县| 巴林左旗| 安远县| 彰化县| 乐至县| 石渠县| 福州市| 牡丹江市| 类乌齐县| 广饶县| 淳安县| 扎鲁特旗| 鸡泽县| 荔浦县| 灌阳县| 阳城县| 新巴尔虎右旗| 工布江达县| 尼勒克县| 新余市| 凤庆县| 星座|