總結:
* jQuery中添加自定義或函數方法1,如 $.fn.extend({'aa':function(){}}) 或 jQuery.fn.aa=function(){}, 這種調用時就得這樣,$("#**").aa()
*jQuery中添加自定義或函數方法2,如$.extend({'aa':function(){}}),這種調用時就是這樣$.aa()
* jQuery中添加自定義或函數方法3,(只是在前2種方法的基礎上添加了參數處理,嚴格來說不算一種jQuery 自定義方法)如: $.myFuncThree("www.baidu.com",'hello',myFuncThreeCB);
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body >
<input type="button" value="按鈕" id="myBtn" >
</body>
<script src="js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
})
/**
* jQuery中添加自定義或函數方法1,如$.fn.extend({'aa':function(){}})或jQuery.fn.aa=function(){},這種調用時就得這樣,$("#**").aa()
*/
jQuery.fn.myFuncOne=function(){
alert("我的自定義jquery方法1");
}
jQuery.fn.extend({
'myFuncFour':function(){
alert("我的自定義jquery方法4");
}
})
/**
* jQuery中添加自定義或函數方法2,如$.extend({'aa':function(){}}),這種調用時就是這樣$.aa()
*/
jQuery.extend({
'myFuncTwo':function(){
alert("我的自定義jquery方法2");
}
})
/**
* jQuery中添加自定義或函數方法3,如 $.myFuncThree('/post/getsecurejsonpost',{}, function(data) {});
*/
$.myFuncThree = function(url, data, successCB){
alert("我的自定義jquery方法3,參數:"+url);
if(successCB){//回調
successCB(url);
}else{
alert("沒有回調");
}
}
function myFuncThreeCB(url){
alert("myFuncThreeCB+"+url)
}
/*
* 測試按鈕
*/
$("#myBtn").click(function(){
$("#myBtn").myFuncOne();
$("#myBtn").myFuncFour();
$().myFuncTwo();
$.myFuncThree("www.baidu.com",'hello',myFuncThreeCB);
$.myFuncThree("www.baidu.com",'hello');
})
</script>
</html>
