redio
获取选中的值
$('input[name="switch"]:checked').val();
根据value设置选中
$("input[type=radio][name=switch][value=1]").attr("checked",true);
但有时attr是不起作用的,需要将attr换成prop
$("input[type=radio][name=switch][value=1]").prop("checked",true);
checkbox
获取选中的值
var id_array=new Array();
$('input[name="sdayWeek"]:checked').each(function(){
id_array.push($(this).val());
});
var idstr=id_array.join(',');
根据索引设置checkbox
$($('input[name="sdayWeek"]').get(0)).attr('checked',true)
根据值选中
var str = 'a,b,c'
$(str.split(",")).each(function (i,e){
$("input[name='ts_'][value='"+e+"']").prop("checked",true);
});
重置checkbox
$('input:checkbox').removeAttr('checked');
select
获取选中的值
$('#name').find('option:checked').val()
设置值
$("#time [value='0']").attr('selected',true)