Blogger Information
Blog 35
fans 3
comment 0
visits 25124
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月16日js变量循环使用
随风
Original
682 people have browsed it

变量、函数的定义

`<!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>`

parseInt isNaN 函数使用

`<!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">

  1. function save() {
  2. var age = document.getElementById('username').value;
  3. //装换为数字
  4. age = parseInt(age);
  5. console.log(typeof(age));
  6. if(isNaN(age)){
  7. return alert('请输入你的年龄');
  8. }
  9. if(age>100||age<0){
  10. return alert('你的年龄输入错误');
  11. } if(age>=0 && age<=100){
  12. return alert('你的年龄'+age);}
  13. }

</script>
</body>
</html>`

小结

初步学了js的语法,基本有了了解。

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post