单选按钮检查w / jQuery [英] Radio Button Check w/ jQuery

查看:78
本文介绍了单选按钮检查w / jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过循环遍历页面上的所有单选按钮,并提醒用户其中一个未选中某个特定问题,最好的方法是什么?

What would be the best way to loop through all radio buttons on my page and alert the user if one of them is unchecked for a particular question?

注意:在一页上有多个问题。

Note: there are multiple questions on one page.

<li>
  <fieldset>
  <h3>What music do you listen to?</h3>  

        <ul class="answerList">
            <li>
                <input type="radio" id="choice_22" name="answer8" value="1" class=""/>
                <label for="choice_22" class="">Heavy Metal  </label>
            </li>
            <li>
                <input type="radio" id="choice_23" name="answer8" value="2" class=""/>
                <label for="choice_23" class="">Pop music</label>
            </li>
            <li>
                <input type="radio" id="choice_24" name="answer8" value="3" class=""/>
                <label for="choice_24" class="">Oh, a mix of stuff </label>
            </li>
         </ul>
       </fieldset>   
      </li>


推荐答案

if (undefined === $("input[name='answer8']:checked").val()) {
    // do something
}

这篇关于单选按钮检查w / jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆