jquery uses examples of OOP mode class classes _jquery

Source: Internet
Author: User

This article illustrates how jquery uses the OOP mode class class. Share to everyone for your reference, specific as follows:

I find it convenient to use class to manage the various function of jquery, and the code is very readable. I used to like to build file writing function, and then include files, then find a function is more trouble. No class is used to manage function convenience. Crap said no more.

First, oop.html

<! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Two, build a oop.js

 function oop () {//define variable var AAA = this;
    Initialize this.init = function () {aaa.addnotice ();
    Aaa.unchange ();
  return AAA; //Add function This.addnotice = function () {$ ("input[type= ' text ']"). each (function () {$ (this). Focus (FU
        Nction () {if (). val () = = $ (this). attr (' notice ')) {$ (")". Val ("");
          . blur (function () {if (). val () = $ (this). attr (' notice ') | | $.trim ($ (this). val ()) = = "") {
        $ (this). Val ($ (this). attr (' notice '));
    }
      });
  }); //Add function This.cleannotice = function () {$ ("input[type= ' text ']"). each (function () {if ($ (). val () = $
      (this). attr (' notice ')} {$ (this). Val ("");
  }
    });
        //Add function This.unchange = function () {$ ('. Select '). Bind (' Change ', function () {if ($). val () = = ' 0 ') {
      Alert (' Noselect ');
      }else{Alert ($ (this). Val ());
  }
    }); }
}

You're interested in testing yourself.

I hope this article will help you with the jquery program design.

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.