单击提交按钮后,我有一个搜索文本框,文本框值保留,但是当我重新加载页面时,文本框值仍在文本框中,如何在重新加载/刷新页面后删除文本框的值。
<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>
给我一个帮助或建议以解决它。
谢谢你。
$(document).ready(function () {
$("#form1").submit(function () {
window.localStorage['text1_val'] = $("input[name = 'text1']").val();
});
$(window).load(function () {
$("input[name = 'text1']").val(window.localStorage['text1_val']);
window.localStorage['text1_val'] = '';
});
});
<form id="form1" method="post">
<input type="text" name="text1">
<input type="submit">
</form>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句