jay61439476
11/11/2016 - 1:40 AM

jQuery操作checkbox-select-radio等

jQuery操作checkbox

$('select').on('change', function (e) {
    var optionSelected = $("option:selected", this);
    var valueSelected = this.value;
    ....
});
// http://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery/426276#426276

/**
 * jQuery 1.6+
 * Use the new .prop() method:
 **/
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);


/**
 * jQuery 1.5.x and below
 * The .prop() method is not available, so you need to use .attr().
 **/
$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);



/**
 * Any version of jQuery
 *  HTMLInputElement's .checked property
 **/
$('.myCheckbox')[0].checked = true;
$('.myCheckbox')[0].checked = false;