我在单击提交按钮后有一个搜索文本框文本框值保留,但是当我重新加载页面文本框值仍然在文本框中时,如何在重新加载/刷新页面后删除文本框的值。
<script>
$(document).ready(function(){
document.getElementById("text1").value = localStorage.getItem("item1");
});
$(window).on('beforeunload', function() {
localStorage.setItem("item1",document.getElementById("text1").value);
});
</script>
HTML。
<td>
<form action="/searchemp" method="post" >
Selected Employee <input type="text" name="EmployeeName" id="text1">
<input type ="submit" value="check">
</form>
给我一个帮助或建议来解决它。
谢谢。
答案 0 :(得分:1)
array_udiff
答案 1 :(得分:0)
默认情况下,页面加载时文本框值为空。 我想你的问题是由于存储和从本地存储中获取值。 负责文本外观的代码
$(document).ready(function(){
document.getElementById("text1").value = localStorage.getItem("item1");
});
答案 2 :(得分:0)
为什么不清除本地存储?
$(window).unload(function() {
window.localStorage.removeItem(item1);
});
代码未经过测试,但这应该会给你一个想法......