删除属性“已检查"复选框 [英] Remove attribute "checked" of checkbox

查看:38
本文介绍了删除属性“已检查"复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当发生错误时,我需要删除一个复选框的已检查"属性.

.removeAttr 函数不起作用.任何的想法?:/

HTML

<div data-role="controlgroup" data-type="horizo​​ntal" data-mini="true" style="margin-left: auto; margin-right: auto; width: 100%;文本对齐:居中;"><input type="checkbox" id="captureImage" name="add_image" class="custom"/><label for="captureImage" data-icon="checkbox">Image</label><input type="checkbox" id="captureAudio" name="add_audio" class="custom"/><label for="captureAudio" data-icon="checkbox">Audio</label><input type="checkbox" id="captureVideo" name="add_video" class="custom"/><label for="captureVideo" data-icon="checkbox">视频</label>

Javascript

$("#captureImage").live("change", function() {//$("#captureImage").prop('checked', false);//这里工作if($("#captureImage:checked").val() !== undefined) {navigator.device.capture.captureImage(function(mediaFiles) {console.log("作品");}, 函数(异常){$("#captureImage").prop('checked', false);//在这里不起作用_callback.error(异常);}, {限制:1});}});/*$("#captureAudio").live("change", function() {if($("#captureAudio:checked").val() !== undefined) {navigator.device.capture.captureAudio(功能(媒体文件){console.log("音频");}, 功能() {$("#captureAudio").removeAttr('checked');_callback.error;}, {限制:1});}});$("#captureVideo").live("change", function() {if($("#captureVideo:checked").val() !== undefined) {navigator.device.capture.captureVideo(功能(媒体文件){console.log("视频");}, 函数(异常){$("#captureVideo").prop('checked', false);_callback.error(异常);}, {限制:1});}});*/

解决方案

抱歉,我用上面的代码解决了我的问题:

$("#captureImage").live("change", function() {if($("#captureImage:checked").val() !== undefined) {navigator.device.capture.captureImage(function(mediaFiles) {console.log("作品");}, 函数(异常){$("#captureImage").removeAttr('checked').checkboxradio('refresh');_callback.error(异常);}, {});}});

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

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

HTML

<div data-role="controlgroup" data-type="horizontal" data-mini="true" style="margin-left: auto; margin-right: auto; width: 100%; text-align: center;">
    <input type="checkbox" id="captureImage" name="add_image" class="custom" />
    <label for="captureImage" data-icon="checkbox">Image</label>
    <input type="checkbox" id="captureAudio" name="add_audio" class="custom" />
    <label for="captureAudio" data-icon="checkbox">Audio</label>
    <input type="checkbox" id="captureVideo" name="add_video" class="custom" />
    <label for="captureVideo" data-icon="checkbox">Video</label>
</div>

Javascript

$("#captureImage").live("change", function() {
    // $("#captureImage").prop('checked', false); // Here Work

    if($("#captureImage:checked").val() !== undefined) {
            navigator.device.capture.captureImage(function(mediaFiles) {
            console.log("works");
        }, function(exception) {
            $("#captureImage").prop('checked', false); // Not Works Here
            _callback.error(exception);
        }, {limit: 1});
    }
});

/*
$("#captureAudio").live("change", function() {
    if($("#captureAudio:checked").val() !== undefined) {
            navigator.device.capture.captureAudio(function(mediaFiles) {
            console.log("audio");
        }, function() {
            $("#captureAudio").removeAttr('checked');
            _callback.error;
        }, {limit: 1});
    }
});

$("#captureVideo").live("change", function() {
    if($("#captureVideo:checked").val() !== undefined) {
            navigator.device.capture.captureVideo(function(mediaFiles) {
            console.log("video");
        }, function(exception) {
            $("#captureVideo").prop('checked', false);
            _callback.error(exception);
        }, {limit: 1});
    }
});
*/

解决方案

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);
        }, {});
    }
});

这篇关于删除属性“已检查"复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆