【发布时间】:2011-06-16 06:12:18
【问题描述】:
我发现了一些令人惊讶的事情:
<html>
<head>
<script type="text/javascript">
function f()
{
document.getElementById("h").value++;
document.getElementById("x").value++;
}
</script>
</head>
<body>
<form>
<input type="hidden" name="hidden" id="h" value="5"/>
<input type="text" id="x" value="5"/>
<input name='clear' type='reset' id='clear' value='Clear'>
</form>
<button type="button" onclick="f()">Increment</button>
<button type="button" onclick="alert(document.getElementById('h').value)">Show hidden</button>
</body>
</html>
在 Firefox 4.0.1 中尝试此操作,单击清除始终会将文本输入重置为 5,但从不重置隐藏字段。
我(和其他人)根本没想到会出现这种行为:我们预计隐藏值也会被重置!
谁能指出解释为什么隐藏输入被重置按钮区别对待的文档或规范?
也欢迎解释为什么这种行为是可取的。
【问题讨论】:
-
重置后隐藏字段的值是多少?
-
@Oltarus 与重置前相同。例如。如果我点击“增量”按钮 5 次,它变成 10,点击重置后保持 10。
标签: html forms reset hidden-field