简体   繁体   中英

Javascript + Radio Button / CheckBox Validation

在Plain Ole的Javascript中,我是否需要使用循环遍历单选按钮/复选框以查看是否已选中它们,或者是否有更简单的方法?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM