/*
Hello Everybody, let's write a jquery plugin, do not always use jquery, but even plug-ins can not write.
Ha ha, joking.
When you see this log, you can be sure that you are a fan of jquery.
Say JS is very casual language, very casually, want to write how to write.
And look at this code.
*/
var jquery = new Object ();//or var jquery = {};
Jquery.method = function (args) {
Alert ("Hello," + args);
}
Jquery.method ("Henry");
/*
Hey, too obvious, you'll see "Hello,henry" pop-up messages. Is this code huge and simple?
Of course, you will naturally think of this method. As follows:
*/
<script language= "javascript" src= "Jquery.js" ></script>
<script language= "JavaScript" >
Jquery.method = function () {
Alert ("Hello,this is Me defined method");
}
Jquery.method ();
</script>
/*
The effect is as you wish. But not the best. Because, a good frame must be left to the Hello interface.
It is best to use it. Should be as follows:
*/
Jquery.extend ({
Method:function () {
Alert ("Hello,this is Me defined method");
}
});
Jquery.method ();
/*
Good, the effect is still the same. But this is the best, why? Because, when your function needs
When adding a parameter, you need to use the default parameter if the other person does not add the parameter. At this time, your design
The benefit is coming, the IT ^.^:
*/
Jquery.extend ({
Method:function (options) {
var defaults = {
Name: ' Henry ',
Sex: ' Male '
};
Jqu Ery.extend (defaults,options); So, all your parameters are coming in.
Alert ("Hello," + Defaults.name + ", you are" + defaults.sex);
}
});
Jquery.method ();
Jquery.method ({
Name: "Yourname",
Sex: "Sex"
});
//Anyway, you can invoke the plugin I wrote. Oh, oh, yes.
/*
There is also the HA, need to remind you, if you read my written analysis of jquery source code or the analysis of their own jquery source code
You will have different feelings. The above is an extension of the static method, which means you don't have to select any element to use the method directly through the
jquery class. The following describes how an element is manipulated. You simply change the Jquery.extend () to the
JQuery.fn.extend ();
*/
JQuery.fn.extend ({
Method:function (options) {
var defaults = {
Name: "Henry",
Sex: "Male"
};
Jquery.extend (defaults,options); So, all your parameters are coming in.
Alert ("Hello," + Defaults.name + ", you are" + defaults.sex);
Return $ (this);/Don't forget to go back and implement the link call.
}
});