一、用的jquery的radio的change事件:當元素的值發生改變時,會發生 change 事件,radio選擇不同name值選項的時候恰巧是值發生改變
表單單選框
<input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot
<input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer
$(document).ready(function() {
// jquery的radio的change事件 $('input[type=radio][name=bedStatus]').change(function() { if (this.value == 'allot') { alert("Allot Thai Gayo Bhai"); } else if (this.value == 'transfer') { alert("Transfer Thai Gayo"); } }); });
1. 獲取radio選中的value.
$('input:radio[name=bedStatus]:checked').val();
2. 選擇 radio 按鈕(這里的下標取決於有幾個name為bedStatus的按鈕)
$('input:radio[name=bedStatus]:nth(0)').attr('checked',true);
或者
$('input:radio[name=bedStatus]')[0].checked = true;
3. 重置 radio 按鈕.
$('input:radio[name=bedStatus]').attr('checked',false);
二、jquery的change事件
<input type="radio" name="bedStatus" class="symbols_radio" checked="checked" value="allot">Allot
<input type="radio" name="bedStatus" class="symbols_radio" value="transfer">Transfer
$(function () { $(".symbols_radio").change(function () { console.log(this.value); // allot console.log(this.name); // bedStatus });
三、jquery的click事件:監聽type=radio的click事件
$(':radio').clcik(function(){ var value = $(this).vale() //獲取選中的radio的值 });