How to check a radio button with jQuery?

前端 未结 30 2089
独厮守ぢ
独厮守ぢ 2020-11-22 08:12

I try to check a radio button with jQuery. Here\'s my code:

30条回答
  •  盖世英雄少女心
    2020-11-22 08:55

    I use this code:

    I'm sorry for English.

    var $j = jQuery.noConflict();
    
    $j(function() {
        // add handler
        $j('#radio-1, #radio-2').click(function(){
    
            // find all checked and cancel checked
            $j('input:radio:checked').prop('checked', false);
    
            // this radio add cheked
            $j(this).prop('checked', true);
        });
    });
    
    
    Radio buttons

提交回复
热议问题