我在这里阅读了很多主题,但是没有找到解决方案,并且尝试了很多建议。因此,我希望以这种方式获得帮助。 我喜欢读取复选框状态,并在使用pagerefresh检查带有参数checkbx = 1的url和未检查参数checkbx = 0时发送。执行时,我不能取消选中该复选框。它立即重置回选中状态。但是地址行中的网址显示为... checkbx = 0!?!
预先感谢, 这是我的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" value="test" id="check"><label for="check">Item</label>
<script>
$(function () {
$('#check').prop("checked", !!localStorage.getItem("darkMode"));
$('#check').on("click", function() {
var url;
if ($(this).is(":checked")) {
localStorage.setItem('darkMode', 'true');
$('img').attr('src', '/full_logo_transparent.png');
$('link#hueman-main-style-css').attr('href', '/darkstyle.min.css');
console.log('Dark Mode enabled');
url = 'index1.php?checkbx=1';
} else {
localStorage.setItem('darkMode', 'false');
$('link#hueman-main-style-css').attr('href', '/main.min.css');
console.log("No Dark Mode");
url = 'index1.php?checkbx=0';
}
window.location.href = url;
});
});
</script>
答案 0 :(得分:0)
我在没有JS的朋友的帮助下解决了这个问题。
$che = '';
if($_SESSION['proc_all'] == 1) $che = ' checked';
?>
<input type="checkbox"<?php echo $che; ?> onclick="window.parent.location='<?php echo $_SERVER['SCRIPT_NAME']."?aktion=1&todo=uebersicht&proc_all=chenge"; ?>'" class="diasel"><label for="check"> Checkbox</label>
还是谢谢!