求助---变量被重置问题---求助
以下这段代码 变量 var t=0;老是被重置。请各位老师帮我看看为什么。==================================================================================
<html>
<head>
<meta charset="UTF-8">
<div id="div" style="width:10000px; height:50px">
<h1> 测试 </h1>
</div>
<script>
<!--var d = document.getElementById("div");
<!--d.style.backgroundColor = "blue";
</script>
</head>
<form id="f1">
匹配字符:
<input type="text" id="RR1" style="width:500px;height:30px" value="41.22.22.22.13"><hr>
<!录入数据:<input type="text" id="RR" onchange="myFunction()" onkeypress="myFunction()">
录入数据:<input type="text" id="RR" style="width:500px;height:30px" onkeypress="myFunction()" > <br>
<button id="ftt" onclick="myFunction()">保存</button>
</form>
<body>
<script>
var oTxt = document.getElementById('RR').focus(); <!--锁定焦点
var all1 = new Array();
var t = 0;
console.log(t)
function myFunction() {
var input1=document.getElementById('RR').value;
var input2=document.getElementById('RR1').value;
var patt1 = new RegExp(input2);
var x = "";
if (event.keyCode == 13) {
if ((patt1.test(input1) == true) && (undefined != input1) && ("" != input1)) {
x = "YES"
all1[t] = input1;
++t;
document.getElementById('RR').value = ""
document.getElementById('DF1').innerHTML = all1;
console.log(t)
console.log(all1)
} else {
x = "NO"
}
}
document.getElementById("DF").innerHTML = x;
}
</script>
判断:
<output id="DF"></output>
<hr>累计:
<output id="DF1"></output>
<hr>计数:
<output id="DF2"></output>
<hr>
</body>
</html>