【发布时间】:2020-08-06 10:25:21
【问题描述】:
我想重新实现 jQuery 函数。
例如.attr()。
我发现了一些线程,例如this。
所以我尝试了类似的方法:
HTMLElement.prototype.attr = (pAttributeName, pAttributeValue) => {
if(pAttributeValue){
this.setAttribute(pAttributeName, pAttributeValue);
} else {
return this.getAttribute(pAttributeName);
}
};
但它不起作用。我必须先在构造函数中初始化元素吗?
【问题讨论】:
-
什么“没用”?你检查错误控制台了吗?
-
是的,什么都没有,但@User863 有答案! :D
-
不是真的,因为有不同的问题!
标签: javascript jquery