Home > Web Front-end > JS Tutorial > body text

Various methods of jquery custom functions_jquery

WBOY
Release: 2016-05-16 17:04:41
Original
1084 people have browsed it
Copy code The code is as follows:

//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

Copy code The code is as follows:

// 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"
});

Copy code The code is as follows:

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();
Copy code The code is as follows:

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()
Copy code The code is as follows:

Method 3:

$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
Calling method: $.postJSON('/post/getsecurejsonpost',{ }, function(data) {});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template