<h1>用户顾客列表</h1> <div > <p>姓名</p> <input type="text" id="name" /> <p>职业</p> <input type="text" id="career" /> <p>电话</p> <input type="text" id="phone" /> <script type="text/javascript"> var myname = document.getElementById("name"); var str = localStorage.getItem("inputText"); if (str) { myname.value = str; } window.onbeforeunload = function () { localStorage.setItem("inputText",myname.value); } </script> <script type="text/javascript"> var mycareer = document.getElementById("career"); var str = localStorage.getItem("inputText"); if (str) { mycareer.value = str; } window.onbeforeunload = function () { localStorage.setItem("inputText",mycareer.value); } </script> <script type="text/javascript"> var myphone = document.getElementById("phone"); var str = localStorage.getItem("inputText"); if (str) { myphone.value = str; } window.onbeforeunload = function () { localStorage.setItem("inputText",myphone.value); } </script> </div> <button onclick="location.href='edit.jsp' ">保存</button>如何让第一页每个输入框的的内容都依次出现在第二页的输入框里
时间: 2023-11-27 12:50:31 浏览: 123
您可以在第一页的保存按钮点击事件中,将输入框的内容存储到localStorage中,然后在第二页的输入框中读取localStorage的值。具体实现如下:
第一页代码:
```
<h1>用户顾客列表</h1>
<div>
<p>姓名</p>
<input type="text" id="name" />
<p>职业</p>
<input type="text" id="career" />
<p>电话</p>
<input type="text" id="phone" />
<button onclick="saveData()">保存</button>
</div>
<script>
function saveData() {
var name = document.getElementById("name").value;
var career = document.getElementById("career").value;
var phone = document.getElementById("phone").value;
localStorage.setItem("name", name);
localStorage.setItem("career", career);
localStorage.setItem("phone", phone);
location.href = "edit.jsp";
}
</script>
```
第二页代码:
```
<h1>用户顾客列表</h1>
<div>
<p>姓名</p>
<input type="text" id="name" />
<p>职业</p>
<input type="text" id="career" />
<p>电话</p>
<input type="text" id="phone" />
</div>
<script>
var nameInput = document.getElementById("name");
var careerInput = document.getElementById("career");
var phoneInput = document.getElementById("phone");
nameInput.value = localStorage.getItem("name");
careerInput.value = localStorage.getItem("career");
phoneInput.value = localStorage.getItem("phone");
</script>
```
这样就可以实现第一页每个输入框的内容都依次出现在第二页的输入框里了。
阅读全文