1
原型选择器$
,$$
...等返回扩展对象Element
。但有时我需要简单的,而不是扩展,HTMLElement
对象。我怎样才能使用Prototype选择器?使用原型选择器获取HTMLElement
原型选择器$
,$$
...等返回扩展对象Element
。但有时我需要简单的,而不是扩展,HTMLElement
对象。我怎样才能使用Prototype选择器?使用原型选择器获取HTMLElement
你不能。 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