好久没更新了
This commit is contained in:
51
js/demo/digui&bibao.html
Normal file
51
js/demo/digui&bibao.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!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>
|
||||
Reference in New Issue
Block a user