简体   繁体   English

jQuery:如何覆盖特定元素的默认方法(即html,append)?

[英]jQuery: how to override default methods (i.e html, append) for particular element?

So for example I what that after automaticaly execute come code after I call el.html("...") how do I override the cored method for specific element? 那么例如我在调用el.html(“...”)之后自动执行后的代码是什么?如何覆盖特定元素的核心方法?

I found that http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm but I can not get how override core method only for a particular element. 我发现http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm但我无法获得如何仅为特定元素覆盖核心方法。

Why not just filter the current object and loop through the items you want? 为什么不过滤当前对象并循环遍历所需的项目? Something like this should work: 这样的事情应该有效:

(function(){
    var original = jQuery.fn.append;

    jQuery.fn.append = function(){
        this.filter("yourselector").each(function(){
            // Do stuff
        });

        return original.apply(this, arguments);
    }
})();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM