Saya perlu menghapus atribut "telah memeriksa" dari satu checkbox ketika kesalahan terjadi.
Yang .removeAttr fungsi tidak bekerja. Ada ide? :/
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});
}
});
*/
Anda bisa mencoba $(ini)
:
$("#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});
}
});
menggunakan .removeAttr()
pada boolean atribut seperti memeriksa
, dipilih
, atau readonly
juga akan mengatur sesuai yang bernama properti untuk palsu
.
Oleh karena itu dihapus ini diperiksa atribut
$("#IdName option:checked").removeAttr("checked");
Saya menggunakan prop atribut untuk dicentang
yang checkbox
ketika kesalahan terjadi.
Anda don't perlu untuk menggunakan menghapus properti untuk dicentang anda centang.
$('input#IDName').prop('checked', false);
Hal ini bekerja dengan baik bagi saya. Berharap ini akan bekerja untuk anda juga.
Maaf, saya memecahkan masalah saya dengan kode di atas:
$("#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);
}, {});
}
});