html:<p id='p'></p>
js:
HTMLElement.prototype.sayHello=function(){
console.log(this); // 获取的是HTMLElement.prototype对象
// 我想获取的是p元素,怎样才能获取到?
}
var p=document.getElementById('p');
p.sayHello();
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Don't do that
http://perfectionkills.com/extending-native-builtins/
题主,我试了一下没问题啊,可以正常获取到啊,而且获取到的类型正是p元素啊,而且我专门做了类型测试,显示获取到的数据类型也没问题啊~