如何制作一个功能去追逐元素
这个问题在这里已经有了答案:
你可以使用原型来实现它
// `getElementById` returns a `Element` object so extend it's prototype
Element.prototype.someFunction = function(){
// this.somethig
}
document.getElementById("element").someFunction();
Element.prototype.someFunction = function() {
console.log(this.value)
}
document.getElementById("element").someFunction();
<input value="abc" id="element" />
您正在寻找prototypes
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype
element.prototype.someFunction = function(){
this.doSomething(); // this refers to element
}
链接地址: http://www.djcxy.com/p/30071.html