如何在文本框中保存文字?
当我重新加载页面时,该文本框将被删除。
我试过这个。
<td align='left' bgcolor='#cfcfcf'><input type="text" name="txtfield" value="" placeholder="input your text" localstorage.setitem(name) /></td>
答案 0 :(得分:0)
试试这个:
<html>
<body>
<td align='left' bgcolor='#cfcfcf'>
<input type="text" name="txtfield" id="txtfield" value=""
placeholder="input your text" onchange="storeitem(this.value)"/>
</td>
<script language="javascript">
function storeitem(val){
localStorage.setItem('txtfield', val)
}
function loaditem(){
var txtfield = document.getElementById('txtfield');
txtfield.value = localStorage.getItem('txtfield');
}
window.onload = loaditem;
</script>
</body>
</html>