• 判断、条件判断、循环、跳转语句



    <html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf8"> <title>my third javascript file</title> </head> <body> hello,world! <br/> <div style="background:pink;500px;height:400px;padding: 10px;"> <from name="form1" action="" method="post" id="form1"> <table style="border:2px solid red;padding:10px;"> <tr> <th colspan="2" bgcolor="AliceBlue">用户注册</th> </tr> <tr > <td><label for="username">用户名:</td> <td><input name="username" type="text" id="username"></input> </label> </td> </tr> <tr> <td><label for="password1">密码:</td> <td><input name="password1" type="password" id="password1"></input> </label> </td> </tr> <tr> <td><label for="password2">确认密码:</td> <td><input name="password2" type="text" id="password2"></input> </label> </td> </tr> <tr> <td> <input name="submit" type="button" class="" onClick="return loginCheck(form1);" value="提交"/> </td> <td> <input name="submit" type="button" class="" value="问候" onClick="return greet();"/> </td> </tr> <tr> <td> <input name="submit" type="button" class="" onClick="return whichDay();" value="今天周几呢?"/> </td> <td> <input name="submit" type="button" class="" value="一百累加结果是多少" onClick="return tenAdd();"/> </td> </tr> <tr> <td> <input name="submit" type="button" class="" onClick="return jishuAdd();" value="100以内的奇数和?"/> </td> <td> <input name="submit" type="button" class="" value="求大于100数之和" onClick="return big100Add();"/> </td> </tr> <tr> <td> <!--如果函数内需要用双引号,但外面包含双引号,可以用单引号代替!!!--> <input name="submit" type="button" class="" onClick="return countDay('12/8/2015');" value="距离约定的半年还有多久?"/> </td> <td> <input name="submit" type="button" class="" value="开心一点" onClick="return cde();"/> </td> </tr> </table> </form> <from name="form2" action="" method="post" id="form2"> <table style="border:2px solid red;padding:10px;"> <tr> <th colspan="2" bgcolor="AliceBlue">输入年龄告诉你人生阶段</th> </tr> <tr > <td><label for="age">请输入您的年龄:</td> <td><input name="age" type="text" id="age"></input> </label> </td> </tr> <tr> <td> <!--如果函数内需要用双引号,但外面包含双引号,可以用单引号代替!!!--> <input name="submit" type="button" class="" onClick="return yourlife(form2);" value="人生阶段"/> </td> <td> <input name="submit" type="button" class="" value="开心一点" onClick="return cde();"/> </td> </tr> </table> </form> </div> <script language="javascript"> //条件判断语句,if语句 function loginCheck(form) { var name1=document.getElementById("username").value; var pwd1=document.getElementById("password1").value; var pwd2=document.getElementById("password2").value; if (name1 == ""||pwd1=="") { alert("请输入用户名或者密码!"); } else if(pwd1!=pwd2) { alert("两次密码输入不一致!"); } else { alert("你可以提交啦~~~"); } } //条件判断语句,if语句。点击“问候”按钮,会有惊喜哟 function greet() { var now=new Date(); var hour=now.getHours(); if (hour>5&&hour<12) alert("上午好!"); else if(hour>12 && hour<21) alert("good afternoon!"); else alert("good night~~~"); } //条件判断语句,switch语句;今天是星期几 function whichDay() { var now1=new Date(); var day1=now1.getDay(); var week; switch (day1) { case 1: week="星期一"; break; case 2: week="星期二"; break; case 3: week="星期三"; break; case 4: week="星期四"; break; case 5: week="星期五"; break; case 6: week="星期六"; break; default: week="星期日"; break; } alert("今天是:"+week); } //循环语句,while ,do...while function tenAdd() { //循环语句,while /* var i=1; var result=i; while (i<100) { i=i+1; result=result+i; } alert(result); */ //循环语句,do...while var i=1; var result=i; do { i=i+1; result=result+i; }while(i<100); alert(result); } //循环语句,for 100以内的奇数和 function jishuAdd() { var s=0; for(var n=1;n<100;n+=2) { s=s+n; } alert(s); } //跳转语句,continue,中止本次循环,求大于100数之和 function big100Add() { var array1=new Array(110,300,45,69,250); var sum=0; for(var m=0;m<array1.length;m++) { if (array1[m]<100) {continue; } sum=sum+array1[m]; } alert(sum); } //跳转语句,break,退出包含在最内层的循环或者退出一个switch语句; function countDay(Intime) { var now=new Date(); var dreamDay= new Date(Intime); var leave=dreamDay.getTime()-now.getTime(); var oneday=1000*60*60*24; var leaveday=Math.floor(leave/oneday); if(leaveday>1) alert("距离和自己约定的半年还有"+leaveday+"天!"); } function cde() { alert("快过生日啦,许个愿望~"); } function yourlife(form2) { var age2=document.getElementById("age").value; if (age2>0 && age2<=18) { alert("未成年");} else if (age2<=30) { alert("奋斗的黄金阶段!");} else if(age2<=50) { alert("享受奋斗的果实吧,黄金阶段!"); } else { alert("希望能够安享晚年!"); } } </script> </body> </html>
  • 相关阅读:
    iOS 音频视频图像合成那点事
    Android低功耗蓝牙(BLE)使用详解
    android实现超酷的腾讯视频首页和垂直水平网格瀑布流一揽子效果
    基于vue单页应用的例子
    Android 6.0 超级简单的权限申请 (Permission)
    ubuntu创建Centos7镜像&&配置运行环境
    Scikit-learn方法使用总结
    解决TensorFlow最新代码编译错误问题
    jQuery 基础
    数据交换格式 —— JSON(JavaScript Object Notation)
  • 原文地址:https://www.cnblogs.com/sunshine-habit/p/4903126.html
Copyright © 2020-2023  润新知