Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在刷新页面后保持复选框处于选中状态_Javascript_Php_Jquery_Html_Checkbox - Fatal编程技术网

Javascript 如何在刷新页面后保持复选框处于选中状态

Javascript 如何在刷新页面后保持复选框处于选中状态,javascript,php,jquery,html,checkbox,Javascript,Php,Jquery,Html,Checkbox,我有一个下拉框,当从下拉框中选择时,它会显示数据。 此外,我在每个td上方都有一个复选框,用于隐藏此java脚本执行的列,如果用户选中该复选框并在下拉框中选择另一个值,则选中的复选框将不会显示 下面是选中复选框时隐藏列的代码 我想测试,如果用户选中了复选框,并在下拉框中选择了另一个值,那么选中的复选框将不会显示任何值 我怎么能这样呢 <input type='checkbox' style='margin:-19px 0 0 732px; border: 1px solid grey;

我有一个下拉框,当从下拉框中选择时,它会显示数据。 此外,我在每个td上方都有一个复选框,用于隐藏此java脚本执行的列,如果用户选中该复选框并在下拉框中选择另一个值,则选中的复选框将不会显示

下面是选中复选框时隐藏列的代码

我想测试,如果用户选中了复选框,并在下拉框中选择了另一个值,那么选中的复选框将不会显示任何值 我怎么能这样呢

<input type='checkbox' style='margin:-19px 0 0 732px;   border: 1px solid grey;' name='9xx'/>9xx
<input type='checkbox' style='margin:-19px 0 0 36px;   border: 1px solid grey;' name='6xx'/>6xx  
<input type='checkbox' style='margin:-19px 0 0 30px;   border: 1px solid grey;' name='12xx'/>12xx
<input type='checkbox' style='margin:-19px 0 0 21px;   border: 1px solid grey;' name='14xx'/>14xx
<input type='checkbox' style='margin:-19px 0 0 26px;   border: 1px solid grey;' name='10xx'/>10xx
<input type='checkbox' style='margin:-19px 0 0 31px;  border: 1px solid grey;' name='8xx'/>8xx
<input type='checkbox' style='margin:-19px 0 0 31px;  border: 1px solid grey;' name='11xx'/>11xx

<script>
$("input:checkbox:not(:checked)").each(function() {
    var column = "table ." + $(this).attr("name");
    $(column).show();
});

$("input:checkbox").click(function(){
    var column = "table ." + $(this).attr("name");
    $(column).toggle();
});

</script>
9xx
6xx
12xx
14xx
10xx
8xx
11xx
$(“输入:复选框:未(:选中)”)。每个(函数(){
var column=“table.”+$(this.attr(“name”);
$(column.show();
});
$(“输入:复选框”)。单击(函数(){
var column=“table.”+$(this.attr(“name”);
$(列).toggle();
});

对其使用本地存储

下面是一个JSFIDLE示例。

背后的代码:

HTML代码:

<input type="checkbox">

对其使用localStorage

下面是一个JSFIDLE示例。

背后的代码:

HTML代码:

<input type="checkbox">

将复选框的状态放在cookie中,并在页面加载时使用它初始化复选框。可能重复@Barmar为什么在地球上人们仍然希望使用cookie来处理这些事情。我认为我们应该开始使用
localStorage
。将复选框的状态放入cookie中,并在页面加载时使用它初始化复选框。可能重复@Barmar为什么在地球上人们仍然希望使用cookie来处理这些事情。我认为我们应该开始使用
localStorage
。此解决方案将选中该页面上可用的所有
复选框,即使您选中一个复选框。是的,我知道。但是任何熟悉jQuery的人都可以通过一个复选框编辑此代码:)这并不难。此解决方案将选中该页面上可用的所有
复选框,即使您选中一个复选框。是的,我知道。但是任何熟悉jQuery的人都可以通过一个复选框编辑这段代码:)这并没有那么难。