<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="ex"></div>
<input id='sky' name='name'>
<button onclick="myFunc()">Click me</button>
<script>
function myFunc() {
var ex = document.getElementById('ex');
var demo = document.getElementById('sky').value;
var l = localStorage;
l.saveData = demo;
console.log(l.saveData);
console.log('called me');
ex.innerHTML = l.saveData;
}
</script>
</body>
</html
如何在我的cordova应用程序中使用纯js保存用户输入? 在下面的代码l.saveData中保存它,但刷新时未保存。如何使其工作?
答案 0 :(得分:1)
答案 1 :(得分:-1)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="ex"></div>
<input id='sky' name='name'>
<button onclick="myFunc()">Click me</button>
<script>
function myFunc() {
var ex = document.getElementById('ex');
ex.innerHTML = localStorage.getItem("data_name");
var demo = document.getElementById('sky').value;
localStorage.setItem("data_name", demo);
}
</script>
</body>
</html