开发者

run jquery function on element. what is wrong with this code?

开发者 https://www.devze.com 2023-02-10 14:10 出处:网络
What is wrong with this code? $(function()开发者_如何学运维 { function testfunction() { $(this).addClass(\'testing\');}

What is wrong with this code?

$(function()开发者_如何学运维 {
    function testfunction() { $(this).addClass('testing');}
    $('.tester').testfunction();
});


testfunction() is not added to the jQuery function stack.

If you want to be able to call it on an arbitrary object, you should add it to the jQuery function stack:

$.fn.testfunction = function() {
   this.addClass('testing');
};

$('.tester').testfunction(); // success!

You should take a look at jQuery's Plugins/Authoring page for more information on how to properly write plugins.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号