jquery獲取radio值實例

字號:


    本文實例講述了jquery獲取radio值的方法,分享給大家供大家參考。具體如下:
    單選組radio:
    復(fù)制代碼 代碼如下:$("input[@type=radio][@checked]").val();
    單選組 radio:
    復(fù)制代碼 代碼如下:$("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項目為當(dāng)前選中項
    獲取一組radio被選中項的值
    復(fù)制代碼 代碼如下:var item = $('input[@name=items][@checked]').val();
    radio單選組的第二個元素為當(dāng)前選中值
    復(fù)制代碼 代碼如下:$('input[@name=items]').get(1).checked = true
    jquery老的版本
    復(fù)制代碼 代碼如下:var_name = $("input[@name='radio_name']:checked").val();
    jquery 1.3以后的版本
    復(fù)制代碼 代碼如下:var_name = $("input[name='radio_name']:checked").val();
    獲取radio值的jquery實例:
    復(fù)制代碼 代碼如下:function getra(){
    var_name = $("input[name='isspecialcnt']:checked").val();
    //alert(var_name);
    if(var_name=='1'){
    $("#isspecialcntyes").show();
    $("#isspecialcntno").hide();
    }
    if(var_name=='0'){
    $("#isspecialcntyes").hide();
    $("#isspecialcntno").show();
    }
    }
    <form name="form1" method="post" action="">
    <p>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_0">
    單選</label>
    <br>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_1">
    單選</label>
    <br>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_2">
    單選</label>
    <br>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_3">
    單選</label>
    <br>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_4">
    單選</label>
    <br>
    <label>
    <input type="radio" name="radiogroup1" value="單選" id="radiogroup1_5">
    單選</label>
    <br>
    </p>
    </form>