我有一个登录页面,我正在存储localStorage密钥的值,即使用var unameVar=localStorage.getItem('uname')从登录页面获取的用户名到变量中。现在,我想将unameVar的值分配给一个按钮。简而言之,按钮的名称在页面加载时应为unameVar。在这方面需要帮助

javascript

<script>
    var unameVar=localStorage.getItem('uname');;
    console.log(unameVar)
</script>


html

<button class="btn btn-link" > This value needs to be changed
</button>

最佳答案

id添加到按钮,然后从localStorgae检索值后,从jquery库使用text添加文本

$('#buttonID').text(unameVar.trim())

10-06 08:05