我可以替换像removeChild这样的标准DOM函数吗? [英] Can I replace s standard DOM functions like removeChild?

查看:104
本文介绍了我可以替换像removeChild这样的标准DOM函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将一些节点从父节点中删除之前,我可以替换像removeChild这样的标准DOM函数来显示例如警报吗?类似的东西,但我的例子有错误

Can I replace s standard DOM functions like removeChild to show for example alert before some node removed from parent? Something like that but my example is with errors

var original = node.removeChild;
node.removeChild = function(node, original){
    alert('message');
    original(node);
}


推荐答案

如果你想申请这个整个文档执行此操作

If you want to apply this across the document do this

var original = Node.prototype.removeChild;
Node.prototype.removeChild = function(node) {
    //custom logic
    original.apply(this, arguments);
}

如果您只想将更改应用于所选节点,那么

If you want to apply the change only to a selected node then

var original = node.removeChild;
node.removeChild = function(node){
    //custom logic
    original.apply(this, arguments);
}

这篇关于我可以替换像removeChild这样的标准DOM函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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