Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在TXT字段中保存文本,不起作用吗?_Javascript_Css_Html - Fatal编程技术网

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语法错误。。。