html中的复选框问题 [英] Checkbox problem in html

查看:51
本文介绍了html中的复选框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个复选框,以便在网页上永久提交。问题是当页面刷新或打开时它会消失。我使用Mozila Firefox并希望在表格中添加复选框,该复选框保持不变,直到再次更改为止。我用这种方式,只是想做复选框提交它的价值...(我写了< html>,< title>和其他标签,但这里没有显示。)



I want to make a check box to submit it self permanently on the webpage. The problem is that it goes away back when the page is refreshed or opened back. I use Mozila Firefox and want to add check box in the table that remains unchanged till it is changed again. I use this way, just wanna make check box to submit it's value... (I have written <html>, <title> and other tags, but not shown here.)

<table border ="5" bgcolor ="white">
 <th> SA2 Examanation Time Table </th>
<tr><td><b> Date</td>
<td><b>Subject </td>
<td><b> Done? </td>
</tr>
<td><font color ="green"> 23rd of Febuary </td>
<td> Sanskrit </td> <td> <input type="checkbox">
<tr>
<td><font color ="aqua"> 25th of Feruary </td>
<td> Science </td>

推荐答案

解决方案1有一个问题:它使用 localStorage 对象,它会污染浏览器数据,因为它必须是永久性的。使用 sessionStorate 会好得多。



我们假设您必须解决更一般的问题:保存并恢复几个控件的状态。有些浏览器会在页面重新加载时恢复这些数据,有些则不会。所以,我轻松开发了一个通用解决方案。一个小问题是Web存储机制无法直接存储复杂对象,因此您还需要使用JSON序列化:

The Solution 1 has one problem: it uses localStorage object, which contaminates the browser data as it has to be permanent. It's much better to use sessionStorate.

Let's assume you have to solve more general problem: save and restore the states of several controls. Some browser will restore this data on page reload, some won't. So, I easily developed an universal solution. One little problem is that the Web storage mechanism cannot directly store complex objects, so you also need to use JSON serialization:
var persistence = {
   key: "your unique key",
   store: function(someObject) {
      sessionStorage.setItem(this.key, JSON.stringify(someObject));
            }, //store
   load: function() {
      var item = sessionStorage.getItem(this.key);
      if (item)
         return JSON.parse(item);
   } //load
} //persistence

// for example, let's save you have some data in checkbox and some textarea:
var checked = // take from your control
var text = // take from your control
var savedData = {checked:checked, text:text};

// you can use
persistence.store(savedData);

// and later (on page load) you can restore this data:
var restoredData = persistence.Load();
if (restoredData) { // the check is important
   // use restored data restoredData.checked and restoredData.text
}





-SA


Refer : HTML:在页面刷新后检查复选框 [ ^ ]
Refer: HTML: keeping checkbox checked after page refresh[^]


这篇关于html中的复选框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆