从原型迁移到 jquery

发布于 2024-08-06 17:52:49 字数 274 浏览 1 评论 0原文

我正在将 js 库从原型迁移到 jquery。但是,我不知道如何替换以下代码:

var utilityMethods = {     
        autoHide : function(element) {
               //...
}

Element.addMethods('SPAN', utilityMethods);

Is there a jQuery equals forextending the DOM?

谢谢

I am migrating my js lib from prototype to jquery. However, I don't know how to replace the following code:

var utilityMethods = {     
        autoHide : function(element) {
               //...
}

Element.addMethods('SPAN', utilityMethods);

Is there a jQuery equivalent for extending the DOM?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你手 2024-08-13 17:52:49

您可以像这样扩展 JQuery 对象:

var utilityMethods = {     
    autoHide : function(element) {
           //...
    }
};

jQuery.fn.extend(utilityMethods);

更多信息: http://docs.jquery.com/Core/ jQuery.extend

You extend JQuery objects like so:

var utilityMethods = {     
    autoHide : function(element) {
           //...
    }
};

jQuery.fn.extend(utilityMethods);

More info: http://docs.jquery.com/Core/jQuery.extend

牵你手 2024-08-13 17:52:49

实际上,jQuery 特意避免扩展 DOM。最近完成了从 Prototype 到 jQuery 的迁移,这对我来说是卖点之一。相反,您扩展 jQuery 本身。使用 jQuery 选择 DOM 对象将为您提供一个包含对一个或多个 DOM 对象的引用的 jQuery 对象。 jQuery 对象上的任何方法调用(包括您的自定义实用程序方法)都会对该 jQuery 对象引用的 DOM 元素进行操作。

Actually, jQuery specifically avoids extending the DOM. Having recently completed a migration from Prototype to jQuery, this was one of the selling points for me. Instead, you extend jQuery itself. Selecting a DOM object with jQuery gives you a jQuery object that contains a reference to one or more DOM objects. Any method calls on the jQuery object (including your custom utility methods) operate on the DOM elements referenced by that jQuery object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文