Home >Web Front-end >JS Tutorial >Jquery plug-in development notes compilation_jquery

Jquery plug-in development notes compilation_jquery

WBOY
WBOYOriginal
2016-05-16 18:11:58961browse

I have no choice but to write an article myself so that I can remember it later!
First post the plug-in code with comments

Copy the code The code is as follows:

( function ($) {
//Extend
$.fn.extend({
//Plug-in name
height: function (options) {
//Default parameters
var defaults = {
color: 'red'
};
//Override the default parameters
var opts = $.extend(defaults, options);
//Main function
return this .each(function () {
//Activate event
var obj = $(this);
obj.click(function () {
alert(opts.color);
} );
});
}
})
})(jQuery);
//The following (jQuery) must be like this, Q must be capitalized, j cannot be capitalized, Otherwise, something goes wrong.

The following is the usage code
Copy the code The code is as follows:

@{
ViewBag.Title = "Home Page";
}
@section Header{


}

@ViewBag.Message


< p>
To learn more about ASP.NET MVC visit http://asp.net/mvc< ;/a>.



It’s very simple. In fact, there are other ways to develop Jquery plug-ins. I just feel that this method is better and more readable. good.

Jquery plug-in is written here!