Writing jquery Plugins

Source: Internet
Author: User

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <title></title>    <Scripttype= "Text/javascript"src= "Scripts/jquery-1.4.1.js"></Script>    <Scripttype= "Text/javascript">        $(function () {            (function ($) {                varMethods={show:function() {alert ('This is show'); }} $.fn.test= function(opt) {varSettings={color:"Red", FontSize:'36px', refresh:function() {alert ('This is settings refresh');                    }                    }; if (typeofopt== "string") {alert (Array.prototype.slice.call (arguments,1)); returnmethods[opt].apply ( This, Array.prototype.slice.call (arguments,1)); //Array.prototype.slice.call (arguments, 1) is the get parameter 1 for the second argument                    }                    Else {                        varoptnew=$.extend (settings, opt); //There is no need to have this package in the $ number as $ (this), because this is already a jquery object.                         //$ (this) equivalent to $ ($ (' #element '))alert (optnew.fontsize); $( This). css ({color:optnew.color,"font-size": Optnew.fontsize});                        //Settings.refresh ();                    alert (Optnew.refresh);            }                };            }) (JQuery); //$ (' div '). Test ({color: ' Blue ', fontSize: "100px", Refresh:function () {alert (' This is opt refresh ');});            $('Div'). Test ("Show","This is 2 Canshu"); //the method that invokes the plug-in first parameter is the method name, the second parameter is an additional parameter that can be passed to show        })    </Script></Head><Body><Div>Test</Div></Body></HTML>

Writing jquery Plugins

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.