checkbox default checked is not working! I tried to fix it, but I can not find where is the error here? I tried that
<div class="onoffswitch" style="margin: 0 auto;">
<input type="checkbox" class="avalbacheckbox onoffswitch-checkbox" id="AvButtonAutoGames" checked="checked"/>
<label class="onoffswitch-label" for="AvButtonAutoGames">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
and that
<div class="onoffswitch" style="margin: 0 auto;">
<input type="checkbox" class="avalbacheckbox onoffswitch-checkbox" id="AvButtonAutoGames" checked="checked"/>
<label class="onoffswitch-label" for="AvButtonAutoGames">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
My js code
$('input.avalbacheckbox').on('change', function() {
$('input.avalbacheckbox').not(this).prop('checked', false);
});
function AvBackgroundImages(e) {
if (e.target.className == 'AvGbtn') {
localStorage.setItem('a_games', "0");
localStorage.setItem('a_flags', "0");
localStorage.setItem('a_christmas', "0");
localStorage.setItem('a_pink', "0");
localStorage.setItem('a_green', "0");
localStorage.setItem('a_doccat', "0");
localStorage.setItem('a_animals', "0");
localStorage.setItem('a_nature', "0");
localStorage.setItem('a_fish', "0");
localStorage.setItem('a_3d', "0");
localStorage.setItem('a_movies', "0");
localStorage.setItem('a_cars', "0");
localStorage.setItem('a_motorcycle', "0");
localStorage.setItem('a_colors', "0");
localStorage.setItem('a_shqip', "0");
var favImage = e.target.style.backgroundImage;
localStorage.setItem('image', favImage);
document.body.style.backgroundImage = favImage;
console.log(favImage);
}
}
document.onclick = AvBackgroundImages;
function AvBackgroundImage() {
var favImage = document.body.style.backgroundImage;
var image = localStorage.getItem('image');
if (image === '') {
document.body.style.backgroundImage = favImage;
} else {
document.body.style.backgroundImage = image;
}
}
window.onload = function(){
AvBackgroundImage();
};
//* games *//
avalbagames = document.getElementById('AvButtonAutoGames');
avalbagames.onclick = function() {
if(document.getElementById('AvButtonAutoGames').checked) {
localStorage.setItem('a_games', "1");
localStorage.setItem('a_flags', "0");
localStorage.setItem('a_christmas', "0");
localStorage.setItem('a_pink', "0");
localStorage.setItem('a_green', "0");
localStorage.setItem('a_doccat', "0");
localStorage.setItem('a_animals', "0");
localStorage.setItem('a_nature', "0");
localStorage.setItem('a_fish', "0");
localStorage.setItem('a_3d', "0");
localStorage.setItem('a_movies', "0");
localStorage.setItem('a_cars', "0");
localStorage.setItem('a_motorcycle', "0");
localStorage.setItem('a_colors', "0");
localStorage.setItem('a_shqip', "0");
localStorage.setItem('image', randomURL);
} else {
localStorage.setItem('a_games', "0");
}
};
b_games = localStorage.getItem('a_games');
if (b_games === "1") {
document.getElementById('AvButtonAutoGames').checked=true;
var selector=$("#AvGamesGalleryImages > span");
var imageURL=[];
for(var i=0;i<selector.length;i++)
{
var bg=$("#AvGamesGalleryImages > span ")[i].style["backgroundImage"];
var startIndex=bg.indexOf("(");
var EndIndex=bg.indexOf(")");
imageURL.push(bg.substring(startIndex+1,EndIndex));
}
var randomURL = imageURL[Math.floor(Math.random() * imageURL.length)];
$("body").css("background-image", "url(" + randomURL + ")");
} else {
document.getElementById('AvButtonAutoGames').checked=false;
}
this is all my code, I tried to fix it, but I can not find where is the error here? the problem is on html, or on js code? before I asked you this question checkbox set to checked = false not working and checked="checked" not working in chrome
Aucun commentaire:
Enregistrer un commentaire