我想要一个数组(也转换为localStorage值)框,其中'#textInput'的值每次都添加到localStorage,但是刷新并输入新值后,新值不会添加到localStorage,但取代它.我相信这是因为刷新后来自用户[]的数据设置为null,但不知道如何修复它
var users = new Array();
var valueChanger = 1;
alert(localStorage.getItem('usernames'));
function addValue() {
var newUser = $('#textInput').val();
users.push(newUser);
localStorage.setItem('usernames', users);
alert(localStorage.getItem('usernames'));
}
Run Code Online (Sandbox Code Playgroud) 我想提醒文本框topValue的值,但是当调用solve()时,会出现一个文本框,但是没有文本/值/数字
这是我的代码:
var topValue = document.getElementById('topValue').value
function solve() {
alert(topValue);
}
$('#solveButton').click(function () {
solve();
});
Run Code Online (Sandbox Code Playgroud)