JQ获取及选中radio及select的值

寻技术 JS脚本 / JAVA编程 2023年07月08日 175

JQ获取radio的值

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

JQ获取select值

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

JQ设置select指定值选中

$("#pass").val('ABC');//值为ABC的选中

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);


关闭

用微信“扫一扫”