单选按钮选中、取消

<input type="radio" name="xxx">
$(function() {
$(‘input:radio’).click(function () {

    1. //alert(this.checked);
    2. var domName = $(this).attr('name');
    3. var $radio = $(this);
    4. // if this was previously checked
    5. if ($radio.data('waschecked') == true) {
    6. console.log($radio.data('waschecked') == true);
    7. $radio.prop('checked', false);
    8. //$("input:radio[name='radio" + domName + "']").data('waschecked',false);
    9. $radio.data('waschecked', false);
    10. } else {
    11. console.log($radio.data('waschecked') == true);
    12. $radio.prop('checked', true);
    13. //$("input:radio[name='radio" + domName + "']").data('waschecked',true);
    14. $radio.data('waschecked', true);
    15. }
    16. });
    17. });

猜你喜欢

转载自www.cnblogs.com/ming-blogs/p/10289036.html