How to uncheck checkbox using jQuery Uniform library

后端 未结 12 2168
再見小時候
再見小時候 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 23:00

    Looking at their docs, they have a $.uniform.update feature to refresh a "uniformed" element.

    Example: http://jsfiddle.net/r87NH/4/

    $("input:checkbox").uniform();
    
    $("body").on("click", "#check1", function () {
        var two = $("#check2").attr("checked", this.checked);
        $.uniform.update(two);
    });
    
    0 讨论(0)
  • 2021-01-29 23:01

    you need to call $.uniform.update() if you update element using javascript as mentioned in the documentation.

    0 讨论(0)
  • 2021-01-29 23:01

     $("#checkall").change(function () {
                var checked = $(this).is(':checked');
                if (checked) {
                    $(".custom-checkbox").each(function () {
                        $(this).prop("checked", true).uniform();
                    });
                } else {
                    $(".custom-checkbox").each(function () {
                        $(this).prop("checked", false).uniform();
                    });
                }
            });
    
            // Changing state of CheckAll custom-checkbox
            $(".custom-checkbox").click(function () {
                if ($(".custom-checkbox").length == $(".custom-checkbox:checked").length) {
                    $("#chk-all").prop("checked", true).uniform();
                } else {
                    $("#chk-all").removeAttr("checked").uniform();
                }
            });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="checkbox" id='checkall' /> Select All<br/>
     <input type="checkbox" class='custom-checkbox' name="languages" value="PHP"> PHP<br/>
     <input type="checkbox" class='custom-checkbox' name="languages" value="AngularJS"> AngularJS<br/>
     <input type="checkbox" class='custom-checkbox' name="languages" value="Python"> Python<br/>
     <input type="checkbox" class='custom-checkbox' name="languages" value="Java"> Java<br/>

    0 讨论(0)
  • 2021-01-29 23:02

    The other way to do is is,

    use $('#check2').click();

    this causes uniform to check the checkbox and update it's masks

    0 讨论(0)
  • 2021-01-29 23:04

    If you are using uniform 1.5 then use this simple trick to add or remove attribute of check
    Just add value="check" in your checkbox's input field.
    Add this code in uniform.js > function doCheckbox(elem){ > .click(function(){

    if ( $(elem+':checked').val() == 'check' ) {
        $(elem).attr('checked','checked');           
    }
    else {
        $(elem).removeAttr('checked');
    }   
    

    if you not want to add value="check" in your input box because in some cases you add two checkboxes so use this

    if ($(elem).is(':checked')) {
     $(elem).attr('checked','checked');
    }    
    else
    {    
     $(elem).removeAttr('checked');
    }
    

    If you are using uniform 2.0 then use this simple trick to add or remove attribute of check
    in this classUpdateChecked($tag, $el, options) { function change

    if ($el.prop) {
        // jQuery 1.6+
        $el.prop(c, isChecked);
    }
    

    To

    if ($el.prop) {
        // jQuery 1.6+
        $el.prop(c, isChecked);
        if (isChecked) {
            $el.attr(c, c);
        } else {
            $el.removeAttr(c);
        }
    
    }
    
    0 讨论(0)
  • 2021-01-29 23:05

    Just do this:

    $('#checkbox').prop('checked',true).uniform('refresh');
    
    0 讨论(0)
提交回复
热议问题