求大佬指点迷津
<html>
<body>
<script type="text/javascript">
var str=0;
var focus=function(){
function noNumbers(e)
{
var keynum;
keynum = window.event ? e.keyCode : e.which;
document.onkeydown = function(){
if(keynum==8){
str++;
}
document.getElementById("showtimes").innerHTML = str ;
}
}
}
</script>
<input id="txt1" type="text" onFocus="focus()" onkeydown="noNumbers(event)"/>
</div><pre>消除次数:<p id="showtimes">0</p><pre></div>
</body>
</html>
首先你这个不叫闭包,闭包必须是函数内return函数,其次我觉得你要完成得功能没必要函数嵌套,你可以拆分成两个函数第一个函数调用第二个函数就行,你可以看看闭包https://www.jianshu.com/p/26c81fde22fb