<script>
(function(window, document, undefined) {
function changeSelect(event) {
if(event.target.type=='checkbox' || event.target.type=='radio') {
window.localStorage.setItem(event.target.id, event.target.checked?'checked':'unchecked');
}
else {
window.localStorage.setItem(event.target.id, event.target.value);
}
if(event.target.type=='select'){
window.localStorage.setItem(event.target.id, event.target.value);
}
}
function load(event) {
var i = 0, k, e;
while(i < window.localStorage.length) {
k = window.localStorage.key(i++);
e = document.getElementById(k);
if(e) {
if(e.type=='checkbox' || e.type=='radio') {
e.checked = window.localStorage.getItem(k)=='checked';
}
else {
e.value = window.localStorage.getItem(k);
}
if(e.type=='select'){
alert('karthika');
}
}
}
}
function clearData(event) {
window.localStorage.clear();
}
window.addEventListener('load', load, true);
window.addEventListener('change', changeSelect, true);
window.addEventListener('select', changeSelect, true);
window.addEventListener('keyup', changeSelect, true);
window.addEventListener('click', changeSelect, true);
window.addEventListener('submit', clearData, true);
})(window, document)
</script>
我正在存储表单数据的内存并检索它,当浏览器突然关闭或系统关闭时会出现此问题。
在上面的代码中,我可以检索用户输入,textarea,复选框。但是两种类型的值不显示选择输入,自动输入值取决于其他输入字段
我如何能够显示选择输入值和自动生成的值取决于用户输入。
提前致谢
答案 0 :(得分:1)