批改状态:未批改
老师批语:
<script type="text/javascript">//变量的定义var str='test hello';//函数的定义function myTestFunc(val){console.log('字符串是'+val); //+拼接字符串}myTestFunc(str);</script>
if else
<script type="text/javascript">var num=88;if(num>=90){alert('优秀');}else if(num<90 && num>=80){alert('良好');}else if(num<80 && num>=70){alert('一般');}else if(num<70 && num>=60){alert('及格');}</script>
switch
<script type="text/javascript">var num=78;function myTestFunc2() {switch(true) {//☆☆☆☆☆☆☆☆注意,这里不能写成switch(num)switch一般的用它来做值匹配的,如果范围的匹配就要设置truecase num>=90:console.log('优秀');break;case num>=80 && num<90:console.log('良好');break;case num>=70 && num<80:console.log('中等');break;case num>=60 && num<70:console.log('及格');break;}}myTestFunc2();</script>
1.for循环
function loop1() {for(var i=1;i<10;i++){console.log('i='+i);}}loop1();//数组遍历function loop4() {var arr=['a','b','c','d'];for (var i=0;i<arr.length;i++){//arr.length JavaScript中数组也是一种对象,有属性.lengthconsole.log(arr[i]);}}loop4();
2.while循环
function loop2() {var t=1;while (t<10){console.log('while 循环:t='+t);t++;}}loop2();
3.do while循环
function loop3(){var k=1;do{console.log('do while 循环:k='+k);k++;}while (k<10)}loop3();
<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);if(isNaN(age)){ //NaN(Not a Number,非数)return alert('年龄转换失败');}if (age>100||age<0){alert('请确认您的年龄');return;}alert('您的年龄为'+age+'岁');}</script>
以上知识点各写几个案例,提交到博客上
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号