Jquery input type=radio 的一些常用用法

时间:2022-09-11 08:03:42
  • HTML代码:
    <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" margin-left:12px;">
    <tr>
    <td align="right" width="2%" ><input type="radio" name="n1" id= "n1" value="1" onclick="return f()" /></td>
    <td align="left"width="10%" >精英夏令营</td>
    <td align="right"width="2%"><input type="radio" name="n1" id= "n1" value="2" onclick="return f()" /></td>
    <td align="left" width="10%">童军夏令营</td>
    
    <td align="right"width="2%"><input type="radio" name="n1" id= "n1" value="4"onclick="return f()" /></td>
    <td align="left"width="25%" >魔力音乐剧夏令营</td>
    </tr>
    </table>

     

  • Jquery 拿值并且判断是否选中
        var is_slect_n1 = $("input[type='radio'][name='n1']:checked").length;
        if(is_slect_n1){
    
        }else{
            alert('请选择夏令营');
            return false;
        }

    $(document).on('change', 'input[name="n1"]:radio', function(){
        window.camp = $(this).val();
    });
        if (window.camp == '1') {
            window.camp = '精英夏令营';
        } else if (window.camp == '2') {
            window.camp = '童军夏令营';
        } else if (window.camp == '4') {
            window.camp = '魔力音乐剧夏令营';
        }

     

  • jquery拿option被选中的值

     <select name="age" id="kidage" class="lbk">
                  <option value="6">6岁</option>
                  <option value="7">7岁</option>
                  <option value="8">8岁</option>
                  <option value="9">9岁</option>
                  <option value="10">10岁</option>
                  <option value="11">11岁</option>
                  <option value="12">12岁</option>
                  <option value="13">13岁</option>
                  <option value="14">14岁</option>
     </select>
    <script>
    var kidage =  $("#kidage").find("option:selected").text();
    </script>

     

  • form表单点击submit不跳转
    <form  id="form1" name="form1"  action="" method="post" onsubmit="return check();" target="id_iframe">
    
    <iframe id="id_iframe" name="id_iframe" style="display:none;"></iframe>