jQuery繼承extend用法詳解

來源:互聯網
上載者:User

標籤:diff   blank   jquer   span   fine   end   turn   nbsp   this   

/直接基於jQuery的擴充,判斷是否為空白 $.isBlank = function(obj){   return(typeof(obj)==‘undefined‘||obj==‘‘||obj==null);  } //直接基於jQuery的擴充,去除html標籤,保留內容  $.htmlContent = function(tag){   var reTag = /<(?:.|\s)*?>/g;   return tag.replace(reTag,"");  } //直接基於jQuery的擴充(方式二) $.xy = { sayhello:function(){return "hello";}, saybaybay:function(){return "baybay";} }; //jQuery類層級的擴充 $.extend({ add:function(a,b){return a+b;}, diff:function(a,b){return a-b} }); //jQuery對象層級的擴充 $.fn.extend({  getvalue:function(){  return this.val();   }  });  html代碼<body>  <script type="text/javascript">   document.write("判斷是否為空白:"+$.isBlank(null));  </script>  <span class="myspan"></span>  <script type="text/javascript">   document.write("過濾html標籤:"+$.htmlContent("<html><body><a id=‘a1‘>a標籤</a><div style=‘width:100%‘>div標籤</div>內容</body></html>")+"<br/>");   document.write("擴充自jQuery類的xy的sayhello方法:"+ $.xy.sayhello()+"</br>");   document.write("擴充自jQuery類的xy的sayhello方法:"+ $.xy.saybaybay()+"</br>");   document.write("基於jQuery類的add法:"+ $.add(3,5)+"</br>");   document.write("基於jQuery類的diff法:"+ $.diff(5,3)+"</br>");   document.write("基於自jQuery類對象的擴充getvalue():"+$("<input type=‘text‘ value=‘str‘ />").getvalue()+"<br/>");  </script>  </body>

jQuery繼承extend用法詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.