How to Keep checkbox checked after refresh the page(刷新页面后如何保持复选框选中)
问题描述
我有一个下拉框,当从下拉列表中选择时,它会显示数据.此外,我在每个 td 上方都有一个复选框,用于隐藏由 java 脚本执行的列,如果用户选中该复选框并在下拉框中选择另一个值,则所选复选框将不会显示.
I have a dropdown-box, that when selecting from the drop down its shows the data. Also I have a checkbox above each td, that is used to hide the column this perform by java script,if the user check the checkbox and he select the another value in the drop down box then the selected checkbox will not show.
下面是选中复选框时隐藏列的代码
Below is the code for hiding the column when checkbox selected
我想测试用户是否选中了复选框并在下拉框中选择了另一个值,然后所选的复选框将不会显示任何一个我怎么能这样?
I want to test if the user checked the checkbox and he select the another value in the drop-down box then the selected checkbox will not show can any one How can I that?
<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>
推荐答案
使用localStorage.
这是它的 JSFiddle 示例.链接
Here is JSFiddle Example of it. Link
背后的代码:
HTML 代码:
<input type="checkbox">
JS代码:
$(function(){
var test = localStorage.input === 'true'? true: false;
$('input').prop('checked', test || false);
});
$('input').on('change', function() {
localStorage.input = $(this).is(':checked');
console.log($(this).is(':checked'));
});
这篇关于刷新页面后如何保持复选框选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:刷新页面后如何保持复选框选中


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01