A variety of ways to customize functions in jquery
- 2020-03-30 01:17:27
- OfStack
//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
//The parameter
var aa = function(x){
//The aa and bb variables in the pop-up object x
alert(x.aa + " I succeeded! " + x.bb);
}
$.windowbox = aa;
$.windowbox({
aa: " Ha ha ",
bb: " La! "
});
Method one:
jQuery.fn.setApDiv=function () {
//The apDiv floating layer displays the 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);
}
Method: $("#apDiv").setapdiv ();
Method 2:
//JQuery application extension
jQuery.extend({
//Set the apDiv
setApDiv:function () {
//The apDiv floating layer displays the 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: $.setApDiv();
Summed up a kind of such as $. The extend ({' aa ': the function () {}}), the call is $. Aa (), another such as $. Fn. The extend ({' aa' : the function () {}}), so, when this call aa () $(this).
Method 3:
$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
Call method: $.postJSON('/post/getsecurejsonpost',{}, function(data) {});