当前位置:首页 > 代码片段

JQ获取及选中radio及select的值

时间:2023-01-19 | 栏目:代码片段 | 围观热度:53

JQ获取radio的值

huifu=$("input[name='huifu']:checked").val();

JQ获取select值

pass=$("#pass option:selected").val();

JQ获取checkbox值

pass=$('#tel_sms:checked').val()

JQ给radio或checkbox指定值选中

//radio
$(":radio[class='bk_1_"+cnum+"'][value='" + cxuan + "']").prop("checked", "checked");

//checkbox

$("input[type=checkbox]").removeAttr("checked");//按属性全部取消选中

if($(":checkbox[class='bk_2_"+xuhao+"'][value='" + cxuan + "']").prop("checked")){
  $(":checkbox[class='bk_2_"+xuhao+"'][value='" + cxuan + "']").prop("checked",false);
}else{
  $(":checkbox[class='bk_2_"+xuhao+"'][value='" + cxuan + "']").prop("checked",true);
}

JQ给checkbox指classname选中

<input type="checkbox" name="xuanze_fz" class="PID_123" value=""  />
$(".PID_"+pid).prop("checked",true);