How to uncheck checkbox using jQuery Uniform library

后端 未结 12 2167
再見小時候
再見小時候 2021-01-29 22:04

I have a problem with unchecking a checkbox. Have a look at my jsFiddle, where I am attempting:

   $(\"#check2\").attr(\"checked\", true);
<         


        
相关标签:
12条回答
  • 2021-01-29 22:39
    $("#chkBox").attr('checked', false); 
    

    This worked for me, this will uncheck the check box. In the same way we can use

    $("#chkBox").attr('checked', true); 
    

    to check the checkbox.

    0 讨论(0)
  • 2021-01-29 22:46
    $('#check1').prop('checked', true).uniform(); 
    $('#check1').prop('checked', false).uniform(); 
    

    This worked for me.

    0 讨论(0)
  • 2021-01-29 22:46

    First of all, checked can have a value of checked, or an empty string.

    $("input:checkbox").uniform();
    
    $('#check1').live('click', function() {
        $('#check2').attr('checked', 'checked').uniform();
    });
    
    0 讨论(0)
  • 2021-01-29 22:47

    checkbox that act like radio btn

    $(".checkgroup").live('change',function() { var previous=this.checked; $(".checkgroup).attr("checked", false); $(this).attr("checked", previous); });

    0 讨论(0)
  • 2021-01-29 22:49

    A simpler solution is to do this rather than using uniform:

    $('#check1').prop('checked', true); // will check the checkbox with id check1
    $('#check1').prop('checked', false); // will uncheck the checkbox with id check1
    

    This will not trigger any click action defined.

    You can also use:

    $('#check1').click(); // 
    

    This will toggle the check/uncheck for the checkbox but this will also trigger any click action you have defined. So be careful.

    EDIT: jQuery 1.6+ uses prop() not attr() for checkboxes checked value

    0 讨论(0)
  • 2021-01-29 22:52

    In some case you can use this:

    $('.myInput').get(0).checked = true
    

    For toggle you can use if else with function

    0 讨论(0)
提交回复
热议问题