【发布时间】:2020-12-10 00:47:57
【问题描述】:
您好,我正在处理这行代码,它是一个语言选择器,我能够将 Lang 选择推送到 localstorage,但是如何让页面选择该存储值并保持不变?每次刷新页面后返回默认的英语语言,我用尽了想法谢谢。
<ul>
<li><a lang="en" href="../Index.html">Home</a></li>
<li><a lang="en" href="../Artgallary.html">Art Gallary</a></li>
<li><a lang="en" href="../Riaart.html">Ria Art</a></li>
<li><a lang="en" href="../Riaprojects.html">Ria Projects</a></li>
<li><a lang="en" href="../Videos.html">Videos</a></li>
<li><a lang="en" href="../About.html">About</a></li>
<li><a lang="en" href="../Contact.html">Contact</a></li>
<li><a lang="ar" style="font-size:28px" href="../Index.html">الصفحة الرئيسية</a></li>
<li><a lang="ar" style="font-size:28px" href="../Artgallary.html">معرض اللوحات</a></li>
<li><a lang="ar" style="font-size:28px" href="../Riaart.html">فن الريا</a></li>
<li><a lang="ar" style="font-size:28px" href="../Riaprojects.html">مشاريع الريا</a></li>
<li><a lang="ar" style="font-size:28px" href="../Videos.html">  فيديو  </a></li>
<li><a lang="ar" style="font-size:28px" href="../About.html">   عني   </a></li>
<li><a lang="ar" style="font-size:28px" href="../Contact.html">تواصل معي</a></li>
</ul>
function langChange(selection) {
document.body.setAttribute('lang', selection.value);
storeLanguage(selection.value)
}
function storeLanguage(task) {
let tasks;
if (localStorage.getItem('tasks') === null) {
tasks = [];
} else {
tasks = JSON.parse(localStorage.getItem('tasks'))
}
tasks.push(task)
localStorage.setItem('tasks', JSON.stringify(tasks));
}
【问题讨论】:
-
哪一行代码?
-
对不起,我的英语是我网站的语言选择功能
-
它确实做到了,但它没有保存..它恢复到默认值......
标签: javascript html