<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>原生js测试</title>
<script type="text/javascript">
//onload 和 onunload 事件会在用户进入或离开页面时被触发
window.onload = function(){
alert('进入页面花了多少时间'+new Date().getTime())
}
</script>
</head>
<body>
<span id='test'></span>
<script type="text/javascript">
//1、带参数retur
function aa(argument1, argument2) {
console.log(argument1, argument2) //1 2
return argument1 + argument2
}
console.log(aa(1, 2)) //3
//2、不带参数retur 内部变量;
//在使用 return 语句时,函数会停止执行,并返回指定的值。
function bb() {
var x = 5;
return x;
}
console.log(bb()) //5
//3、直接调用函数
var ele = document.getElementById('test').innerHTML = bb(); //页面显示5
console.log(ele, 'ele') //5 ele
//4、变量的赋值理解
x = 10;
y = 5;
x = y;
console.log(x, 'xxxx'); //5 "xxxx"
//5、三元运算符的运用
var age = 8;
var val = (age > 10) ? 'ok' : 'no'
console.log(val, 'val') //no val
//6.case语句块
var toDay;
var day = new Date().getDay();
switch(day) {
case 0:
toDay = "Today it's Sunday";
break;
case 1:
toDay = "Today it's Monday";
break;
case 2:
toDay = "Today it's Tuesday";
break;
case 3:
toDay = "Today it's Wednesday";
break;
case 4:
toDay = "Today it's Thursday";
break;
case 5:
toDay = "Today it's Friday";
break;
case 6:
toDay = "Today it's Saturday";
break;
}
console.log(toDay,'toDay')//Today it's Tuesday toDay
//7、dom操作;
// document.getElementById(id).innerHTML=new HTML 改变 HTML内容
// document.getElementById(id).style.property=new style 更改样式
// document.getElementById(id).attribute=new value 改变 HTML属性
</script>
</body>
</html>