用cookie保存选择的选项
时间:2015-01-30 17:19 点击:次
每次刷新不会被重置啦
<select name="sex" id="sex" onchange="save()"> <option value="01" selected >男</opton> <option value="02" >女</opton> </select> <input id="s1" type="radio" name="xueli" value="0" onclick="save()"/>本科 <input id="s2" type="radio" name="xueli" value="1" checked onclick="save()"/>专科 <script language="javascript" type="text/javascript"> function save() { selectIndex = document.getElementById("sex").selectedIndex; document.cookie = 'selectIndex =' + selectIndex; radios = document.getElementsByName("xueli"); for (i = 0; i < radios.length; i++) { if (radios[i].checked) document.cookie = 'radioindex =' + i; } } window.onload = function () { var cooki = document.cookie; if (cooki != "") { cooki = "{\"" + cooki + "\"}"; cooki = cooki.replace(/\s*/g, "").replace(/=/g, '":"').replace(/;/g, '","'); var json = eval("(" + cooki + ")"); //将coolies转成json对象 document.getElementById("sex").options[json.selectIndex].selected = true; document.getElementsByName("xueli")[json.radioindex].checked = true; } else save(); } </script>
顶一下
(3)
50%
踩一下
(3)
50%
上一篇:没有了
下一篇:没有了
相关内容:
- QQ群
-
微信
- 返回首页
- 返回顶部