jQuery繼承extend用法詳解
更新時間:2016年10月10日 14:28:08 作者:zz_cl
這篇文章主要為大家詳細介紹了jQuery繼承extend用法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家jQuery繼承extend用法,供大家參考,具體內(nèi)容如下
js代碼
//直接基于jQuery的擴展,判斷是否為空 $.isBlank = function(obj){ return(typeof(obj)=='undefined'||obj==''||obj==null); } //直接基于jQuery的擴展,去除html標簽,保留內(nèi)容 $.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代碼
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript" src="jquery-1.7.js"></script> <script type="text/javascript" src="jquery-1.7.min.js"></script> <script type="text/javascript" src="my.js"></script> <script type="text/javascript"> $(function(){ var br = $("<br/>"); $(".myspan").append(br); }) </script> </head> <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>內(nèi)容</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> </html>
輸出
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 深入理解jquery中extend的實現(xiàn)
- jQuery的extend方法【三種】
- jQuery插件擴展extend的簡單實現(xiàn)原理
- Jquery實現(xiàn)$.fn.extend和$.extend函數(shù)
- jQuery.extend 函數(shù)及用法詳細
- 淺談jquery.fn.extend與jquery.extend區(qū)別
- jQuery中extend函數(shù)詳解
- jQuery中$.extend()用法實例
- jQuery中extend()和fn.extend()方法詳解
- jQuery中extend函數(shù)詳解
- JQuery中extend的用法實例分析
- 淺談jQuery中的$.extend方法來擴展JSON對象
相關文章
15個值得開發(fā)人員關注的jQuery開發(fā)技巧和心得總結【經(jīng)典收藏】
這篇文章主要介紹了15個值得開發(fā)人員關注的jQuery開發(fā)技巧和心得,詳細總結分析了jQuery常用的開發(fā)技巧,需要的朋友可以參考下2016-05-05jquery插件bootstrapValidator表單驗證詳解
這篇文章主要為大家詳細介紹了jquery插件bootstrapValidator表單驗證,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12jQuery + html + css 實現(xiàn)王者榮耀官網(wǎng)首頁效果&nb
這篇文章主要介紹了jQuery + html + css 實現(xiàn)王者榮耀官網(wǎng)首頁效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02JQuery團隊打造的javascript單元測試工具QUnit介紹
元測試又稱為模塊測試,是針對程序模塊(軟件設計的最小單位)來進行正確性檢驗的測試工作。單元測試主要是用來檢驗程式的內(nèi)部邏輯,也稱為個體測試、結構測試或邏輯驅動測試。通常由撰寫程式碼的程式設計師負責進行。2010-02-02