您可以使用有效的 cookie 或会话变量,但更好的是使用您之前存储的计数器的输入隐藏字段。
HTML
<form method="get">
<input type="hidden" value="" name="counter" id="counter" />
..........
..........
</form>
Javascript
<script type="text/javascript">
//http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return 0;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
var ErrorCounter = 0;
$(document).ready(function() {
$("#counter").val(getParameterByName("counter"));
if($('.validmissing').length > 0) {
ErrorCounter = $("#counter").val();
ErrorCounter = 1*ErrorCounter + 1;
$("#counter").val(ErrorCounter);
});
</script>