In Plain Ole' Javascript, do I NEED to use a loop to loop through the radio buttons/checkboxes to see if they are checked or is there a simpler way of doing this?开发者_如何学编程
Yes. It may be most helpful to...
- ...have them all contained in one element, so you can traverse through its children
- ...apply a class name to all of them, to use
document.getElementsByClassName
- ...use
document.getElementsByTagName
(though, the tag is theinput
tag, so you may get other elements as well)
However, that is just getting the elements; but as you've stated, you will still need to iterate through each one to do whatever comparison you like. jQuery will allow you to do this kind of thing more easily, but "Plain Ole' Javascript" cannot.
精彩评论