chrome.storage.local.set / get工作不正常?

时间:2017-07-13 11:23:59

标签: javascript google-chrome-extension

我试图保存用户的电子邮件和密码。我在这里失踪了什么?

这是我的HTML:

<input type="text" name="email" id="email" placeholder="E-mail" />
<input type="password" name="password" id="password" placeholder="Password" />
<button id="import">Import!</button>
<script type="text/javascript" src="popup.js"></script>

这是我的JavaScript:

chrome.storage.local.get('email', function(result) {
    document.getElementById("email").value = result.value;
});

chrome.storage.local.get('password', function(result) {
    document.getElementById("password").value = result.value;
});

document.getElementById("import").addEventListener("click", function() {
    chrome.storage.local.set({'email': document.getElementById("email").value});
    chrome.storage.local.set({'password': document.getElementById("password").value});
}

扼杀,当我刷新页面时,没有保留这些值。

1 个答案:

答案 0 :(得分:0)

应该是:

chrome.storage.local.get('email', function(result) {
    document.getElementById("email").value = result.email;
});

chrome.storage.local.get('password', function(result) {
    document.getElementById("password").value = result.password;
});