Meine local null zurück, und ich weiß nicht, warum, die Lesefunktion nicht verwendet wird, sondern nur für die Hilfe, die ich es trotzdem setzen. Chrome sagt, dass es innerHTML nicht auf null setzen kann, und meine Troubleshooting-Alert-Info gibt auch null zurück, aber der Code geht an das Ende. Jede Hilfe wäre nützlich, danke.
Das Cookie:HTML local Gibt Null
<!doctype html>
<html>
<head>
<cookie>
<script>localStorage.setItem('id',Math.floor(Math.random()*10))
</script>
</cookie>
</head>
<body>
<script>var id = localStorage.getItem('id')
alert(id)</script>
</body>
</html>
Das Script:
<!doctype html>
<html>
<head>
<script>
var theId=localStorage.getItem('id')
function change(id,target){
var info = localStorage.getItem(id);
alert(info)
document.getElementById(target).innerHTML=info;
}
function read(){
var element=document.createElement('h1')
element.innerHTML='You Want To Read'
document.body.appendChild(element)
alert('debug')
}
</script>
</head>
<body>
<input type="button" value="Read" name="read_story" id="read_story"
onclick=read();change(theId,info)>
<p id='info'>initial</p>
</body>
<script>
alert('debug');
</script>
</html>
haben Sie versucht, nur einen harten codierten Wert einstellen und sehen, ob getItem danach funktioniert? – ThisGuyHasTwoThumbs