zoukankan      html  css  js  c++  java
  • JS第三次课

    1、 函数

    function functionName(arg1,arg2…)

    {

      …..

    }

     

    return语句用法

     

    2、 对象

    属性/方法

    var aValues=new Array();

    var myString=new String(“hello world”);

     

    3、 Date对象(var myDate=new Date())

    1) 计算程序执行速度(得到毫秒数)1.html

    2) 方法

    方法

    描述

    getFullYear()

    返回四位数的年份

    getMonth()

    返回月份(当前的月份-1)

    getDate()

    返回日期(从1开始)

    getDay()

    返回星期几(星期天0)

    getHours()

    返回小时数(从1开始)

    getMinutes()

    返回分钟数(从1开始)

    getSeconds()

    返回秒数(从1开始)

    getMilliseconds()

    返回毫秒数(从0开始)

    getTime()

    返回从GMT时间1970年1月1日0点0分0秒经过的毫秒数

     

                例1:

                    var myDate1 = new Date(); //运行代码前的时间
                    for(var i=0;i<3000000;i++);
                    var myDate2 = new Date(); //运行代码后的时间
                    alert(myDate2-myDate1);

                 

                例2:

                   var oMyDate = new Date();
                   var iYear = oMyDate.getFullYear();
                   var iMonth = oMyDate.getMonth() + 1; //月份是从0开始的
                   var iDate = oMyDate.getDate();
                   var iDay = oMyDate.getDay();
                   switch(iDay){
                   case 0:
                  iDay = "星期日";
                  break;
                  case 1:
                  iDay = "星期一";
                  break;
                  case 2:
                  iDay = "星期二";
                  break;
                  case 3:
                  iDay = "星期三";
                  break;
                  case 4:
                  iDay = "星期四";
                  break;
                  case 5:
                  iDay = "星期五";
                  break;
                  case 6:
                  iDay = "星期六";
                  break;
                  default:
                  iDay = "error";
                    }
                  document.write("今天是" + iYear + "年" + iMonth +"月" + iDate + "日," + iDay);

    4、 Math对象

    1) 属性

    Math.LN10

    10的自然对数

    Math.LN2

    2的自然对数

    Math.LOG2E

    以2为底E的对数

    Math.LOG10E

    以10为底E的对数

    Math.PI

    圆周率

    Math.SQRT1_2

    1/2的平方根

    Math.SQRT2

    2的平方根

    2) 方法

    取最大值:Math.max(18,12,22,33)

    取最小值:Math.min(18,2,2,3,1)

    向上舍入:Math.ceil(25.9) //它把数字向上舍入到最接近的整数

    向下舍入:Math.floor(25.6) 

    四舍五入:Math.round(25.6)

    0~1之间的随机数:Math.random() //不包括0和1

    var iNum=Math.floor(Math.random()*100+1) //返回1~100之间的整数包括1和100

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    学区房概念
    VMwareworkstationfull8.0.2591240.exe
    VMwareworkstationfull8.0.4744019.exe
    .net伪静态
    将DataTable中的某一行复制到另一个新的DataTable(转)
    js服务器端控件Label 与TextBox RadioButtonList 与 DropDownList 的值
    Iframe刷新父窗口的几种方式
    记录一下ListItem类的常用的方法
    ASP.net中的Repeater控件嵌套
    记录一条自己常用的分页存储过程
  • 原文地址:https://www.cnblogs.com/banchengping/p/4868452.html
Copyright © 2011-2022 走看看