2012-01-20 50 views

回答

2

你不能。 Prototype.js修改Element的原型,其方法由HTMLElement继承。

$相当于document.getElementById,并返回一个普通元素或null
$$document.querySelectorAll类似,但返回Array而不是NodeList

最简单的方法来证明它,在页面上运行下面的代码,其中的Prototype.js使用:

console.log(Object.getOwnPropertyNames(Element)); 

,而不是仅仅prototype,这个打印整个列表,类似于:

cache,Methods,_attributeTranslations,_returnOffset,_getContentFromAnonymousElement,_insertionTranslations,visible,toggle,hide,show,remove,update,replace,insert,wrap,inspect,recursivelyCollect,ancestors,descendants,firstDescendant,immediateDescendants,previousSiblings,nextSiblings,siblings,match,up,down,previous,next,getElementsBySelector,getElementsByClassName,readAttribute,writeAttribute,getHeight,getWidth,classNames,hasClassName,addClassName,removeClassName,toggleClassName,observe,stopObserving,cleanWhitespace,empty,descendantOf,scrollTo,getStyle,getOpacity,setStyle,setOpacity,getDimensions,makePositioned,undoPositioned,makeClipping,undoClipping,cumulativeOffset,positionedOffset,absolutize,relativize,cumulativeScrollOffset,getOffsetParent,viewportOffset,clonePosition,childElements,Simulated,extend,hasAttribute,addMethods,ClassNames,childOf,prototype,length,name,arguments,caller