问题
I'm just curious, how can I call a custom function after document.getElementById()? Something like this:
document.getElementById("element").mycustomfunction();
回答1:
Technically you can do this :
Element.prototype.mycustomfunction = function() {
console.log("I don't work on IE7");
};
You can test it easily in your console on this page : type it first and then document.getElementById("notify-container").mycustomfunction();
.
It works. There's not technical problem with it. But it might make it a little harder for maintainers of your applications to trace what happens, it might led to collisions with other plugins doing the same, and it doesn't really add a lot over myPlugin.doSomething(element)
.
来源:https://stackoverflow.com/questions/16752928/how-to-add-custom-function-to-call-after-document-getelementbyid