本文介绍了在Javascript中,可以扩展DOM吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Javascript中,您可以使用其原型对象来扩展现有的类:
In Javascript, you can extend existing classes by using its prototype object:
String.prototype.getFirstLetter = function() { return this[0]; };可以使用这种方法来扩展DOM元素吗?
Is it possible to use this method to extend DOM elements?
推荐答案可以使用Element的原型扩展DOM。但是,这在IE7和更早版本中不起作用。您将需要一次扩展一个特定元素。原型库执行此操作。我建议您查看来源,查看它们是如何完成。
you can extend the DOM by using the Element's prototype. However, this does not work in IE7 and earlier. You will need to extend the specific element, one at a time. The Prototype library does this. I recommend looking through the source to see exactly how it's done.
更多推荐
在Javascript中,可以扩展DOM吗?
发布评论