Javascript 在TXT字段中保存文本,不起作用吗?
如何在文本框中保存文本 当我重新加载页面时,文本框中的文本将被删除 我试过这个Javascript 在TXT字段中保存文本,不起作用吗?,javascript,css,html,Javascript,Css,Html,如何在文本框中保存文本 当我重新加载页面时,文本框中的文本将被删除 我试过这个 试试这个: <html> <body> <td align='left' bgcolor='#cfcfcf'> <input type="text" name="txtfield" id="txtfield" value="" placeholder="input your text" onchange="storeitem(this.value)"/> &
试试这个:
<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>
函数存储项(val){
localStorage.setItem('txtfield',val)
}
函数loaditem(){
var txtfield=document.getElementById('txtfield');
txtfield.value=localStorage.getItem('txtfield');
}
window.onload=loaditem;
是否将值保存在某个位置?对于后期使用。本地存储在元素属性中真的可以这样工作吗?这看起来像是HTML语法错误。。。