//In the jquery anonymous function, use Jquery.extend (); method to create a jquery plugin//In the jquery anonymous function, use the object. property = function to create a jquery plugin(function ($) {Jquery.extend ({jia:function (A, b) {returnA +b; }, Jian:function (A, b) {returnA < b? B-a: A-b; } }); $.sub={sheng:function (A, b) {returnAb; }, Chu:function (A, b) {returnA < b? B/A: A/b; }} JQuery.fn.Insert=function (a) {alert (a); }}) (JQuery)
<script type="Text/javascript"Src="~/jquery-1.7.1.min.js"></script> <script type="Text/javascript"Src="~/jqtest.js"></script> <script type="Text/javascript">function Btn_click () {varA = prompt ("Please enter a number:"); varb = Prompt ("Please enter a number:"); varA = Prompt ("Please enter a number:"); varc =Jquery.jia (A, b); varD =Jquery.jian (A, b); varE =$.sub.sheng (A, b); varf =$.sub.chu (A, b); Alert ("Add:"+ C +", Subtract:"+ D +", Multiply:"+ E +", Divide:"+f); $.fn. Insert ("La la"); } </script>
About the "call" syntax: Call([thisobj [,arg1[, arg2[ ,] [,. ArgN]])
Definition: Invokes one method of an object, replacing the current object with another object.
Description: The call method can be used to invoke a method in place of another object. The call method can change the object context of a function from the initial context to a new object specified by Thisobj. If the Thisobj parameter is not provided, then the Global object is used as the thisobj.
About "This"
In the plug-in method, it may be useful to point to the plug-in's this, and to the event-triggered this, so the event-triggered this is obtained with an event: Event.cuerrnttarget
- Event.currenttarget: Points to the element that the event is bound to, and, as the event bubbles, finds the element
- Event.target: Always points to the element when an event occurs
Constructor property: Always points to the constructor that creates the current object
Each function has a default property of prototype, and this prototype constructor is the default point to this function
JS Package JQ Library for plugins