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