Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用localstorage中的变量更新span_Javascript_Html - Fatal编程技术网

Javascript 使用localstorage中的变量更新span

Javascript 使用localstorage中的变量更新span,javascript,html,Javascript,Html,我试图用另一个脚本中的变量替换html span中的文本 我知道变量被正确传递,因为它显示在控制台中,但无论我尝试什么,我都无法更新文本 有人知道如何解决这个问题吗 document.addEventListener('DOMContentLoaded', ready) } else { ready() } function ready() { window.onload(console.log(localStorage.getItem("total"))) co

我试图用另一个脚本中的变量替换html span中的文本 我知道变量被正确传递,因为它显示在控制台中,但无论我尝试什么,我都无法更新文本 有人知道如何解决这个问题吗

    document.addEventListener('DOMContentLoaded', ready)
} else {
    ready()
}
function ready()
{
    window.onload(console.log(localStorage.getItem("total")))
    costUpdate()
}


function costUpdate ()
{
    var cost = localStorage.getItem("total")
    getElementById("cost-text").textContent = '$' + cost
} ```
我从window.onloadconsole.loglocalStorage.getItemtotal中删除了window.onload``` 我不知道这是为什么,也不知道它是如何干扰的,所以我会把它标记为解决了,但如果有人能向我解释这一点,我将不胜感激