0
我正在尝试在JS中练习范围闭包,我很坚持在Html页上实现范围闭包。 这是一个非常简单的代码,但它不起作用。 这段代码的主要思想是使用功能“增加”按钮事件中“点击”,然后显示在DIV结果:显示关闭HTML页面
(function() {
'use strict'
var showIncrease = document.getElementById("increase").innerHTML;
this.increase= function (strat) {
return function() {
start++;
return start;
}
}
var inc = increase(0);
showIncrease = inc;
}).apply(this);
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<button onclick="inc()">increase</button>
<div id="increase"></div>
<script src="timer.js"></script>
</body>
</html>
它终于做到了,谢谢 – Ilanz