`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>javascript 变量、函数的定义</h2>
<h3>alert console.log </h3>
<!--<input type="text" id="username" value="admin">-->
<script type="text/javascript">
var a=3;
// alert(a);
var b=5;
console.log(a);
function test() {
// alert(b);
console.log(b)
}
// test(b);
function test1() {
var c=3;
alert(c)
}
test1();
</script>
</body>
</html>#if eles switch
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>if eles switch</h2>
</body>
<script type="text/javascript">
var res=5000;
let res1 = 6000;
function test2() {
switch(true) {
case res1>4000:
alert(‘买电脑’);
break;
case (res1<=4000 && res1>2000):
alert(‘买手机’);
break;
default:
alert(‘买游戏机’);
}
}
test2();
function test() {
if(res>4000) {
return alert(‘买电脑’);
}
if(res<=4000 && res>2000) {
return alert(‘买手机’);
}
if(res<=2000 ) {
return alert(‘买游戏机’);
}
}
// test();
function test1() {
if (res>4000){
alert(‘买电脑’);
}else if(res<=4000 && res>2000) {
alert(‘买手机’);
}else {
alert(‘买游戏机’);
}
}
// test1(res);
</script>
</html>#三种循环for while do while
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>三种循环for while do while</h2>
<script type="text/javascript">
function test() {
for (var i=0;i<10;i++){
console.log('i=' +i);
// alert(i);
}
}
// test();
function test1() {
var i=10;
while (i>0) {
i—;
console.log(‘i=’+i)
// console.log(i);
// alert(i);
}
}
// test2();
function test2() {
let i=0;
do{
i++;
console.log(‘i=’+i);
}while (i<10)
}
test2();
</script>
</body>
</html>`
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>parseInt isNaN 函数使用</h2>
<input type="text" id="username" value="" placeholder="请输入你的年龄">
<button onclick="save()">提交</button>
<script type="text/javascript">
function save() {
var age = document.getElementById('username').value;
//装换为数字
age = parseInt(age);
console.log(typeof(age));
if(isNaN(age)){
return alert('请输入你的年龄');
}
if(age>100||age<0){
return alert('你的年龄输入错误');
} if(age>=0 && age<=100){
return alert('你的年龄'+age);}
}
</script>
</body>
</html>`
初步学了js的语法,基本有了了解。