javascript - Using functions from inside a plugin -
I wrote a little jQuery button plugin - it contains a method to apply the onclick function - here is the code
(function ($) {$ .fn.tbutton = function () {this.setFN = function (fn) {alert ("function set.");}};}) (JQuery);
I'm using this code (on a div) to start it:
var button = $ ("# myButton") . TButton ();
Issue now: When trying to implement the setFN function:
button .setFN (function () {dosomething ();});
I am getting an error: button.setFN is not a function
I have tried before but have not changed. help. Anyone knows what is wrong?
You are not returning anything from the Tubutan function so that the value of Tubutan is' do you think it To get it back to the jQuery object, try returning to this
tButton (). Besides, I do not think this is a good way to do this because you are basically expanding jQuery in a non-standard way. One better way would be that Tibbons take a callback function as an argument and apply it to match elements only. I also use a different pattern to define the plugin (similar to the UI plugins).
(function ($) {$ .fn.extend ({tButton: function (callback) {return (., (Callback);}.);}}); $ .TButton = Function (AMM, Callback) {$ (AMM). Click (Callback);};}) (jQuery);
Comments
Post a Comment