jQuery plugin that takes user method -


I am working on a jQuery plugin and I want the user to set a flag (in code) to the right . I already have the necessary flag, I need a route to execute the method passed. For example:

  (function (jQuery) {$ .fn.extend ({pluginName: function (option) {var defaults = {parameter1: 0, method: function () {}} Var (flag) {if option.parameter1 & gt;}} {flag = true;} (flag) {if option} // call user method} jQuery (this) .hide ();}); // end returns} / END counter method}}} // expansion}} // eND function return // jquery object (jquery);  

Users call it this way:

< Pre-> $ ("# divName"). PluginName ({parameter1: 1, method: function () {warning ("test")}}});

Did not test the given code, it If you are trying to do, thank you in advance!

There is no difference between the user-supplied method, such as your example and any other method. Therefore, you can call it the same way as you say to any other method.

For example:

  if (flag) opt.method ();  

If the method takes the argument, you can pass it in the same way, the way you argue in normal ways.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -