How to check a radio button with jQuery?

前端 未结 30 2472
独厮守ぢ
独厮守ぢ 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 used jquery-1.11.3.js

    Basic Enable & disable

    Tips 1: (Radio button type common Disable & Enable)

    $("input[type=radio]").attr('disabled', false);
    $("input[type=radio]").attr('disabled', true); 
    

    Tips 2: ( ID selector Using prop() or attr())

    $("#paytmradio").prop("checked", true);
    $("#sbiradio").prop("checked", false);
    
    jQuery("#paytmradio").attr('checked', 'checked'); // or true this won't work
    jQuery("#sbiradio").attr('checked', false);
    

    Tips 3: ( Class selector Using prop() or arrt())

    $(".paytm").prop("checked", true);
    $(".sbi").prop("checked", false);
    
    jQuery(".paytm").attr('checked', 'checked'); // or true
    jQuery(".sbi").attr('checked', false);
    

    OTHER TIPS

    $("#paytmradio").is(":checked")   // Checking is checked or not
    $(':radio:not(:checked)').attr('disabled', true); // All not check radio button disabled
    
    $('input[name=payment_type][value=1]').attr('checked', 'checked'); //input type via checked
     $("input:checked", "#paytmradio").val() // get the checked value
    

    index.html

提交回复
热议问题