//Method definition
$.windowbox = {
//Define a method aa
aa: function(){
alert("aa");
},
//Define a method bb
bb: function(){
alert("bb");
}
}
$.windowbox.aa(); //Call the aa method in $.windowbox
// Pass parameters
var aa = function(x ){
//Pop up the aa variable and bb variable in object x
alert(x.aa "I succeeded" x.bb);
}
$.windowbox = aa;
$.windowbox({
aa: "Haha",
bb: "LaLa"
});
Method 1:
jQuery.fn.setApDiv=function () {
//apDiv float Layer display position center control
var wheight=$(window).height();
var wwidth=$(window).width();
var apHeight=wheight-$("#apDiv") .height();
var apWidth=wwidth-$("#apDiv").width();
$("#apDiv").css("top",apHeight/2);
$("#apDiv").css("left",apWidth/2);
}
Call method: $("#apDiv").setApDiv();
Method 2:
//jQuery application extension
jQuery .extend({
//Set apDiv
setApDiv:function () {
//apDiv floating layer display position center control
var wheight=$(window).height();
var wwidth=$(window).width();
var apHeight=wheight-$("#apDiv").height();
var apWidth=wwidth-$("#apDiv").width( );
$("#apDiv").css("top",apHeight/2);
$("#apDiv").css("left",apWidth/2);
}
});
Calling method: $.setApDiv();
To sum up a method such as $.extend({'aa':function(){}}), this This is the case when calling $.aa(), and the other is $.fn.extend({'aa':function(){}}). This is how it is called, $(this).aa()
Method 3:
$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
Calling method: $.postJSON('/post/getsecurejsonpost',{ }, function(data) {});