webveuje/js/demo/digui&bibao.html
2021-03-23 10:58:10 +08:00

51 lines
1.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>递归和杨辉三角</title>
</head>
<body>
<button onclick="ljq()">点我加一</button>
<p></p>
<script>
function combine (m, n) {
if (n == 0) {
return 1;
} else if (m == n) {
return 1;
} else {
return combine(m - 1, n) + combine(m - 1, n - 1);
}
}
function put (len) {
for (let i = 0; i < len; i++) {
for (let j = 0; j <= i; j++) {
document.write(combine(i, j) + ' ');
}
document.write('<br/>');
}
}
put(5);
function add(){
var count = 0;
function demo(){
count ++;
console.log("现在的值:"+count);
}
return demo;
}
var counter = add();
function ljq(){counter(); }
// 目的从全局访问add里面的count变量
// 点击调用ljq -> counter-> counter=demo->demo() -> 输出结果
</script>
</body>
</html>