toggle input radio

$(function(){
    $('input[name="rad"]').click(function(){
        var $radio = $(this);

        // if this was previously checked
        if ($radio.data('waschecked') == true)
        {
            $radio.prop('checked', false);
            $radio.data('waschecked', false);
        }
        else
            $radio.data('waschecked', true);

        // remove was checked from other radios
        $radio.siblings('input[name="rad"]').data('waschecked', false);
    });
});

 

<input type="radio" id="aa" name="rad" data-waschecked="true" class="ico-green">

 

posted @ 2016-03-26 10:54  顺其自然²º¹?  阅读(223)  评论(0编辑  收藏  举报