<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js 全局、局部变量计数</title> </head> <body> <p>全局、局部变量计数。</p> <button οnclick="count()">计数!</button> <p id="demo">0</p> <script> let counter = 0; function add_global() { counter += 1; return counter; } let add_local = (function () { let counter = 0; return function () { return counter += 1; } })(); function count() { document.getElementById("demo").innerHTML = add_global(); // document.getElementById("demo").innerHTML = add_local(); } </script> </body> </html>
js 全局、局部变量计数.html
猜你喜欢
转载自blog.csdn.net/weixin_42193179/article/details/105332542
今日推荐
周排行