我正在使用 localStorage,我可以在上一页中存储并在本页中检索它。 (使用警报检查)。
name12=localStorage.getItem("content");
现在我的要求是将其显示到输入字段中并使其不可编辑。
请帮我解决一下。我尝试了不同的方法,但我无法做到正确。
在输入标签中使用onblur="localStorage.setItem(this.name, this.value)
并且还尝试使用
if name_2.value = name12; in script tag
最佳答案
要使字段不可编辑,您可以使用输入字段上禁用的 html 属性。 http://www.w3schools.com/tags/att_input_disabled.asp
要设置字段的默认值,可以使用 html 属性值。在您的情况下,由于该值是动态的,您可能不想在 html 中内联执行此操作。一种可能的解决方案是通过 JavaScript 设置 value 属性,如下所示。
<script type="text/javascript">
var name2 = document.getElementById("name_2");
name2.value = localStorage.getItem("content");;
</script>
关于javascript - 将从 localstorage 检索到的值插入到输入字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29781721/