问题描述:

Got stacked,

I have a simple strikethrough task list html script that works fine, however, I would like to have the browser to store the data and save it persistently so that if I refresh the page or I come back to the task list on a later time I will still have the tasks already done striked.

Here is my html code:


<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>

<title>Demo of Strikethrough JavaScript string object</title>

<script type="text/javascript">

function my_fun(j){

var chkbox ="ckb" + j;

var my_span ="my_span" + j;

var msg = chkbox + " " + my_span;

if(document.getElementById(chkbox).checked){

document.getElementById(my_span).style.textDecoration='line-through';

}else{

document.getElementById(my_span).style.textDecoration='none';

}

}

</script>

</head>

<body>

<form name=form1 method=post action=check.php>

<input type=checkbox id=ckb1 value=1 onclick=my_fun(1);><span id='my_span1'>This is job number 1</span> <br>

<input type=checkbox id=ckb2 value=2 onclick=my_fun(2);><span id='my_span2'>This is job number 2</span> <br>

<input type=checkbox id=ckb3 value=3 onclick=my_fun(3);><span id='my_span3'>This is job number 3</span> <br>

</form>

</body>

</html>

Thank you all

网友答案:

If you want a browser independent approach, you likely want to store this in a cookie, and then read the data back in on load.

You likely want to use a utility library to help you manage the cookie data. Here is a discussion of using jQuery for this.

jquery save json data object in cookie

相关阅读:
Top