如何覆盖appendChild()? [英] how do I override appendChild()?

查看:132
本文介绍了如何覆盖appendChild()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

appendChild = function(message) {
    console.log("intercepted!");
}

使用上面的代码似乎不起作用。

using the code above does not seem to work.

任何人都知道?

推荐答案

您可能想要替换的是 Element.prototype.appendChild ,但这可能是一个坏主意。

What you might want to replace is Element.prototype.appendChild but it's probably a bad idea.

此示例添加文本 intercepted 在插入的元素中:

This example adds the text intercepted in the inserted element :

var f = Element.prototype.appendChild;
Element.prototype.appendChild = function(){f.apply(this, arguments);arguments[0].innerHTML="!Intercepted!"; };
document.body.appendChild(document.createElement("div"));

演示

这篇关于如何覆盖appendChild()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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