checkbox、radiobox、select常用操作

checkbox选中、不选中及事件绑定

//
$('#checkbox').is(':checked'); // get check state
$('#checkbox').prop('checked', true); //check the box
$('#checkbox').on('change', function(){
   // do something
 });
$('#checkbox').on('click', function(){
   // do something
 });

radiobox选中、不选中及组合

// assume two radio in a group 
//
//
$('input[type=radio] :checked')   //get checked radio in group
$('input[type=radio]').filter(':checked') // get checked radio in group
$('#radio1').prop('checked', true) //check the radio
$('#radio1').is(':checked')  //get check state

select选中option及获取值

/*

*/
$('select option:selected').val() //get selected option value
$('select option:selected').text() // get selected option text
$('select').val() //get selected option value
$('select').text()// get all the options text(01), do not do this
$('select').val('v1') //trigger select to select option with value v1
$('select option:first').prop('selected', true) //select the first option

你可能感兴趣的:(checkbox、radiobox、select常用操作)