从原型迁移到 jquery
我正在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样扩展 JQuery 对象:
更多信息: http://docs.jquery.com/Core/ jQuery.extend
You extend JQuery objects like so:
More info: http://docs.jquery.com/Core/jQuery.extend
实际上,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.