我试图将表单的使用限制为例如三次并保存值。然后显示,全部用localStorage。怎么能得到这个?请帮忙。
HTML
<form name=colors>
<input type="Radio" name="colorin" value="white" checked> White
<br>
<input type="Radio" name="colorin" value="red"> Red
<br>
<input type="Radio" name="colorin" value="green"> Green
<br>
<input type="Button" name="" value="Click" onclick="color()">
<div id='output'></div>
</form>
JAVASCRIPT
function color(){
if (localStorage.getItem('thing') === null) {
var i
var colors = document.getElementsByName('colorin')
for (i=0;i<colors.length;i++){
if (colors[i].checked)
var answer = colors[i].value;
}
localStorage.setItem('thing', answer);
var fillin = document.getElementById('output');
fillin.innerHTML=localStorage.getItem('thing');
}
else{
alert('Exists!!!');
}
}