135 lines
3.0 KiB
HTML
135 lines
3.0 KiB
HTML
<!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>Document</title>
|
||
</head>
|
||
|
||
<body>
|
||
<button class="one">A</button>
|
||
<button class="two">B</button>
|
||
<button class="three">C</button>
|
||
<a href=""></a>
|
||
</body>
|
||
<script>
|
||
console.log(window)
|
||
|
||
var name = 250
|
||
// if (name >= 200 && name <= 300 ) {
|
||
// console.log("王一鸣是250");
|
||
// }else{
|
||
// console.log("王一鸣还是250");
|
||
// }
|
||
|
||
if (name < 200 || name > 300) {
|
||
console.log("王一鸣是250");
|
||
} else {
|
||
console.log("王一鸣还是250");
|
||
}
|
||
|
||
var cj = 75,
|
||
fl;
|
||
if (cj < 60) {
|
||
fl = "不及格"
|
||
} else if (cj >= 60 && cj < 70) {
|
||
fl = "及格"
|
||
} else if (cj >= 70 && cj < 80) {
|
||
fl = "良好"
|
||
} else {
|
||
fl = "优秀"
|
||
}
|
||
console.log(fl)
|
||
|
||
|
||
// 只有当i<50成立的时候即ture 才会执行i++。 例:i>50,false,不执行 输出undefined。
|
||
for (var i = 1; i < 50; i++) {
|
||
console.log(i);
|
||
}
|
||
|
||
// 九九乘法表 一层套一层
|
||
|
||
// 外层总共九行,所以定义一个名=公式 自动换行总共九行
|
||
for (var i = 1; i <= 9; i++) {
|
||
var all = ""
|
||
// 内层无数行,所以打印日志在外层,轻松实现换行
|
||
for (var j = 1; j <= i; j++) {
|
||
// all += j + "*" + i + "=" + i*j + ' '
|
||
all += `${j}*${i}=${i*j} `
|
||
}
|
||
all += `</br>`
|
||
// document.write(all)
|
||
|
||
}
|
||
|
||
|
||
var A = new Object({
|
||
Number: 20,
|
||
sex: "男",
|
||
name: "猪"
|
||
})
|
||
|
||
console.log(A);
|
||
console.log(A.name);
|
||
console.log(A["name"]);
|
||
// Key 是基于for in才被访问到的。key可以被定义为各种名称的常量
|
||
// B基于for in才被访问到 所以是局部常量
|
||
for (const B in A) {
|
||
console.log(B)
|
||
}
|
||
|
||
|
||
var A = new Object();
|
||
A.name = "哈1";
|
||
A.age = "哈2";
|
||
console.log(A);
|
||
|
||
FFF = 1
|
||
console.log(FFF);
|
||
// 去掉var,变量提升,且只提升一级
|
||
function a() {
|
||
var b = function () {
|
||
aaa = 1
|
||
}
|
||
console.log(aaa);
|
||
}
|
||
|
||
// 回调函数
|
||
function testa(n) {
|
||
// 执行n,n接收的ttt所以实际执行的是ttt的function,即123
|
||
n()
|
||
}
|
||
var tttt = function () {
|
||
console.log(123);
|
||
}
|
||
testa(tttt)
|
||
|
||
// 回调案例
|
||
function test(call, n) {
|
||
console.log('call', call);
|
||
var a = call()
|
||
n += a
|
||
console.log('n', n);
|
||
}
|
||
|
||
function b() {
|
||
return 1 + 1
|
||
}
|
||
test(b, 2)
|
||
|
||
|
||
// <button class="one">A</button>
|
||
// <button class="two">B</button>
|
||
// <button class="three">C</button>
|
||
// 事件的写法
|
||
// querySelector只能查询第一个
|
||
var all = document.querySelectorAll("button")
|
||
for (var i = 0; i < all.length; i++) {
|
||
all[i].innerText = "你好"
|
||
console.log('all', all[i]);
|
||
}
|
||
</script>
|
||
|
||
</html> |