Remove attribute “checked” of checkbox

后端 未结 9 1167
野的像风
野的像风 2020-12-11 00:11

I need remove the attribute \"checked\" of one checkbox when errors occur.

The .removeAttr function not work. Any idea? :/

HTML

相关标签:
9条回答
  • 2020-12-11 00:40

    Both of these should work:

    $("#captureImage").prop('checked', false);
    

    AND/OR

    $("#captureImage").removeAttr('checked');
    

    ... you can try both together.

    0 讨论(0)
  • 2020-12-11 00:40

    using .removeAttr() on a boolean attribute such as checked, selected, or readonly would also set the corresponding named property to false.

    Hence removed this checked attribute

    $("#IdName option:checked").removeAttr("checked");
    
    0 讨论(0)
  • 2020-12-11 00:41

    try something like this FIDDLE

        try
          {
            navigator.device.capture.captureImage(function(mediaFiles) {
            console.log("works");
             });
          }
    
        catch(err)
          {
            alert('hi');
            $("#captureImage").prop('checked', false);
    
          }
    
    0 讨论(0)
  • 2020-12-11 00:43

    You could try $(this):

    $("#captureAudio").live("change", function() {
        if($(this).val() !== undefined) { /* IF THIS VALUE IS NOT UNDEFINED */
                navigator.device.capture.captureAudio(function(mediaFiles) {
                console.log("audio");
            }, function() {
                $(this).removeAttr('checked'); /* REMOVE checked ATTRIBUTE; */
                /* YOU CAN USE `$(this).prop("checked", false);` ALSO */
                _callback.error;
            }, {limit: 1});
        }
    });
    
    0 讨论(0)
  • 2020-12-11 00:43

    Sorry, I solved my problem with the code above:

    $("#captureImage").live("change", function() {
        if($("#captureImage:checked").val() !== undefined) {
            navigator.device.capture.captureImage(function(mediaFiles) {
                console.log("works");
            }, function(exception) {
                $("#captureImage").removeAttr('checked').checkboxradio('refresh');
                _callback.error(exception);
            }, {});
        }
    });
    
    0 讨论(0)
  • 2020-12-11 00:46

    Try this to check

    $('#captureImage').attr("checked",true).checkboxradio("refresh");
    

    and uncheck

    $('#captureImage').attr("checked",false).checkboxradio("refresh");  
    
    0 讨论(0)
提交回复
热议问题