jquery獲取radio值使用到特殊的選擇器type=radio,為方便大家理解,另附一個jquery實例,想學習的朋友可以看看
單選組radio: $("input[@type=radio][@checked]").val();
單選組radio: $("input[@type=radio]").attr("checked",'2');//設置value=2的項目為當前選中項
獲取一組radio被選中項的值
var item = $('input[@name=items][@checked]').val();
radio單選組的第二個元素為當前選中值
$('input[@name=items]').get(1).checked = true
單選組 radio: $("input[@type=radio]").attr("checked",'2');//設置value=2的項目為當前選中項
jquery老的版本
var_name = $("input[@name='radio_name']:checked").val();
jquery 1.3以后的版本
var_name = $("input[name='radio_name']:checked").val();
看個獲取radio值的jquery實例
- 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();
- (www.survivalescaperooms.com) $("#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>
新聞熱點
疑難解答
圖片精選