1. 程式人生 > >單選按鈕選中、取消

單選按鈕選中、取消

attr inpu pro str on() dom false fun his

<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. });

單選按鈕選中、取消