Home > Q&A > body text
html:<p id='p'></p>
js:HTMLElement.prototype.sayHello=function(){ console.log(this); // 获取的是HTMLElement.prototype对象
// 我想获取的是p元素,怎样才能获取到?
}var p=document.getElementById('p'); p.sayHello();
天蓬老师2017-04-10 17:05:54
Don't do thathttp://perfectionkills.com/extending-native-builtins/
题主,我试了一下没问题啊,可以正常获取到啊,而且获取到的类型正是p元素啊,而且我专门做了类型测试,显示获取到的数据类型也没问题啊~