如何向jQuery添加功能? [英] How to add a function to jQuery?

查看:75
本文介绍了如何向jQuery添加功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义新的jQuery 成员函数的最简单方法是什么?

What's the easiest way to define a new jQuery member function?

这样我可以打电话给类似的人

So that I can call something like:

$('#id').applyMyOwnFunc()

推荐答案

请参阅

在这篇文章中,我想介绍一下 轻松定义自己的功能 jQuery并使用它们.

In this post, I want to present how easy define your own functions in jQuery and using them.

来自帖子:

jQuery.fn.yourFunctionName = function() {
    var o = $(this[0]) // This is the element

    return this; // This is needed so other functions can keep chaining off of this
};

只需使用:

$(element).yourFunctionName();

这篇关于如何向jQuery添加功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆