JQuery plug-in, silly !, Jquery plug-in silly points

Source: Internet
Author: User
Tags beautifier

JQuery plug-in, silly !, Jquery plug-in silly points
Not to mention, directly add the code!

First extend

<! -- Extend extension jQuery is actually adding a static method -->
$. Extend ({
SayHello: function (name)
{
Alert ('hello, '+ (name? Name: 'xxxx') + '! ')
}
});

$ (Function (){
$. SayHello ();
$. SayHello ('hangsan ');
});

Type 2 $. fn
<! -- $. Fn: Add a method to the JQuery object -->
$. Fn. Red = function (){

This. each (function (){
$ (This). append (''+ $ (this). attr ('href '));
});

Return this.css ('color', 'red ');
}



$ (Function (){
$ ("A" ).Red().css ('color', 'Gray ');
});

Third: Comprehensive Utilization

<! -- Comprehensive Utilization -->
$. Fn. MyDesign = function (options ){
Var defaults = {
'Color': 'red ',
'Fontsize': '12pt'
}
Var settings = $. extend ({}, defaults, options)

This. each (function (){
$ (This). append (''+ $ (this). attr ('href '));
});

Return this.css ({'color': settings. color, 'fontsize': settings. fontSize });
}

 

Fourth optimization (Object-Oriented and other details)

; (Function ($, window, document, undefined ){
Var Beautifier = function (ele, options ){
This. defaults = {
'Color': 'yellow ',
'Fontsize': '20pt'
}
This. ele = ele,
This. options = options,
This. setting = $. extend ({}, this. defaults, this. options)
}

Beautifier. prototype = {
Beautify: function (){
Return this.ele.css ({
'Color': this. setting. color,
'Fontsize': this. setting. fontSize
})
}
}

$. Fn. MyDesgin = function (options ){
Var beautifier = new Beautifier (this, options );
Beautifier. beautify ();
}
}) (JQuery, window, document)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.