问题
How well supported is the document.getElements() function. Additionally, is there a javascript reference page that has detailed browser support information somewhere. I usually use the mozilla docs, but I was wondering if there is something better.
I actually can't find any documentation on document.getElements() but when I do things like:
document.getElements("div a");
It works great in chrome, ff, safari, ie8 and ie6-9 via IETester. I think IETester may use the same javascript engine for all browsers though (not sure about that).
回答1:
There is no such thing as document.getElements... I'll bet your coding in Jsfiddle and don't realize that the mootools lib is included ;)
Have a look: http://jsfiddle.net/Zevan/pRKzy/
回答2:
quirksmode.org is a pretty good resource for things like this (though not fully updated on IE9, as it's a moving target at the moment).
Note: they don't have an entry for document.getElements()
specifically (are you sure you're getting this name right?), but in general it's a pretty complete reference, here's an example - check out .querySelectorAll() (which does what you describe...).
回答3:
Probably you are looking for querySelecterAll function:
elementList = parentNode.querySelectorAll(selectors);
This is most handy and much usable function.
To check how your requested feature is supported among browsers you can use "Can I Use" site:
https://caniuse.com/#search=querySelectorAll
On this site you can check not only functions but HTML attributes and CSS capabilities too
来源:https://stackoverflow.com/questions/4363036/document-getelements-support