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
( 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
@{
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!