2009年10月27日 星期二

JQuery - Radio


不知道哪個版本了, 動態的把選取的值取出
$('input:checked[name="xxx"]').val();
$("input[name='privacy.info_freq']").click(function(){ } 綁定後, 用 $(this).val() 
$("input[name=xxx][@type=radio]").attr("checked",'2'); //把位置2 的值 checked
$("input:[name='xxx']:nth(1)").attr("checked","true");
$('input[name=xxx]').get(0).checked //檢查是否選取, 回傳boolean, 也可直接 = 給值
$("#xxx").attr("disabled", "true"); //針對某id來disabled
$("input[name=xxx][@type=radio]").attr("disabled","true"); //這name的radio全部disabled
$("input[name=xxx][@type=radio]").attr("disabled",""); //這name的radio全部 enabled
1.7 的版本如下:

當radio同一個名稱, 且有好幾個的時候要如何指定當中的某一個為 checked,

注意 : 0 為第一個
    $j('input[name="role"][@type=radio]').get(0).checked = true;
    $j('input[name="role"][@type=radio]:nth(0)').attr("checked", true)
    $j('input[name="role"][@type=radio]').first().attr("checked", true);
    $j('input[id="changeRole"][@type=radio]:first').attr("checked", true);    

0 意見: