开发者

Javascript + Radio Button / CheckBox Validation

开发者 https://www.devze.com 2023-04-08 07:04 出处:网络
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 h

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 the input 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号