tru*_*ity 11 html forms reset hidden-field
我发现了令人惊讶的事情:
<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>
Run Code Online (Sandbox Code Playgroud)
在Firefox 4.0.1中尝试此操作,单击"清除"始终会将文本输入重置为5
,但永远不会重置隐藏字段.
我(和其他人)根本没想到这种行为:我们期望隐藏的值也被重置!
任何人都可以指向解释为什么隐藏输入被重置按钮区别对待的文档或规范?
关于为什么这种行为是可取的解释也是受欢迎的.