Jquery plug in writing concise tutorial

  • 2020-03-30 02:27:32
  • OfStack

 

 //; For better compatibility, start with a semicolon
 ;(function($){//Use $as a parameter for the anonymous function
  //$.fn.extend extension
  $.fn.extend({
      "color":function(value){//Color writes its own plug-in method name
       //JQuery provides CSS methods that can be directly written as this.css (" properties ", "values");
       return this.css("color",value);
      }
  });

 })(jQuery);//Jquery is passed here as an argument to an anonymous function

 
 function red(){
  alert($("#div").color()+" Proof that plug-ins are available ");
  alert($("#div").color("red")+" Verify that the plug-in returns one Jquery object ");
  $("#div").color("red");
 }

Examples of using plug-ins in HTML:

 <body>
      <div id="div" onclick="red()">dddddddddddddddd</div>
  </body>


Related articles: