x
1
<p>全局变量计数。</p>
2
<button type="button" onclick="myFunction()">计数!</button>
3
<p id="demo">0</p>
4
<script>
5
var counter = 0;
6
7
function add() {
8
return counter += 1;
9
}
10
11
function myFunction() {
12
document.getElementById("demo").innerHTML = add();
13
}
14
</script>