jquery–判斷checkbox是否被選取

判斷checkbox是否被選取

$(“#your-checkbox-id”).attr(‘checked’,true)

加上判斷可以用
if($(“input#your-checkbox-id”).attr(‘checked’))這種

另外取出radio的值用
$(“input:radio[name=’name_not_id’]:checked”).val()

[checkbox 賦值]
$(“#chk1”).attr(“checked”,”); //設定不打勾
$(“#chk2”).attr(“checked”,true); //設定打勾

[checkbox 取值]
var x=$(“input[name=’fetion’]”).is(“:checked”));
x=true有被打勾,否則為 false

[radio 賦值]
$(‘input[name=”si”]’)[1].checked = true; //radio 賦值==>第二個選項選取
$(“input[name=state][value=’2′]”).attr(‘checked’,true); //radio 賦值==>值為2的那個選取

[radio 取值]
$(“input[name=’inputname’]:checked”).val();

if( typeof(method) == “undefined”) // 注意檢查完全沒有選取的寫法

記下來提醒自己…不要在鬼打牆了>_<||