js数组
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试 js数组</title>
<script>
/* 方式一 */
let a = new Array();
a = new Array(1,1.6,true,'hello',null);
a[98] = 0
console.log(a);
console.log(a.length);
console.log(a[3]);
console.log(a[a.length-1])
/* 方式二*/
let b = [];
b = [1,2.8,false,'hi',null];
console.log(b);
console.log(b.length);
console.log(b[3])
for(let i = 0; i < b.length; i++){
console.log(b[i] + "_+_+_+_+_")
}
for(var i in b){
console.log(i);
console.log(b[i]);
}
</script>
</head>
<body>
</body>
</html>
js函数
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS函数及调用</title>
<script>
/* 方式一fanction function() */
function cal(){
console.log("cal的方法")
}
/* 方法二var function = function() */
var write = function(){
console.log("write的方法")
}
cal();
write();
function fun(){
var y = 0;
for (var i = 1; i < 101; i++) {
if(i % 2 == 0){//过滤偶数
y += i ;//求和
}
}
return y;
}
</script>
</head>
<body>
<button onmouseenter="fun()">fun的方法</button>
</body>
</html>
js对象
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>第一遍JS对象</title>
<script>
/* 方式一 */
function Person(){
}
let p = new Person();
p.name="tony";
p.addr="北京";
console.log(p.name+p.addr);
p.eat=function(){
console.log("吃大餐")
}
console.log(p);
p.eat();
function a(){
window.alert('100'); /* 弹出框 */
window.confirm('确认'); /* 确认框 */
window.prompt("请输入"); /* 输入框 */
window.document; /* 属性,获取网页文档 */
var x = 'hello';
console.log(x.length);
console.log(x.charAt(0));
console.log(x.concat('拼接'));
console.log(x.substring(1,3));
}
</script>
</head>
<body>
</body>
</html>