zoukankan      html  css  js  c++  java
  • Javascri几种常见的数据类型方法

    一丶判断对象是否拥有某种属性和方法

    1.in运算符

    var obj = {name:"zhangsan"};
    alert('name' in obj); //返回 true
    alert('toSring' in obj); //返回 true

    2.hasOwnProperty方法    (判断是不是本身拥有的方法)

    var obj = {name:"zhangsan"};
    obj.hasOwnProperty("name"); //true
    obj.hasOwnProperty("toString"); //false
    //原型链上的属性无法通过hasOwnProperty()检测到

    二丶本地对象

    I.Data对象日期对象处理日期和时间

    <script type="text/javascript">
            var T = window.setInterval(function(){
                var date = new Date();                          //返回当前时间
                  datefullyear = date.getFullYear(),                 //返回当前年数   2017
                  dategetmonth = date.getMonth(),                   //返回当前月份   4
                  dategetday = date.getDay(),                      //返回星期几
                  dategetdate = date.getDate(),                    //返回多少号 日期
                  dategethours = date.getHours(),                   //返回时间--时针
                  dategetminutes = date.getMinutes(),                  //返回时间--分针
                  dategetseconds = date.getSeconds(),                  //返回时间--秒针
                  dategetmillisconds = date.getMilliseconds(),            //返回时间--毫秒针
                  body = document.body,
                  arr = ["日","一","二","三","四","五","六"];
               body.innerHTML = datefullyear + "年" + (dategetmonth+1) + "月"+ dategetdate + "号" + dategethours + "时"
                + dategetminutes + "分" + dategetseconds + "秒"+ "------" + "周" + arr[dategetday];
                },1000);
            </script>

     整体效果如下:时间自动实时刷新

    II.Math()对象

    Math对象时javascript中的一个全局对象不需要用new创建,用来处理复杂的数学运算

    Math.abs(-10);     //求绝对值    10
    Math.round(5.5); //四舍五入 6
    Math.random(); //0-1之间的随机数
    Math.random()+1; //1-2之间的随机数
    Math.random()*10; //0-10之间的随机数
    Math.aqrt(); //返回一个数的平方根,这个数不能是负数  可以为0
    Math.hypot(3,4); //返回参数平方和的平方根
    Math.ceil(); //想上去最小整数
    Math.floor(); //向下取最大整数
    Math.pow(a,b); //a的b次方值
    Math.sign(); //判断一个数值的正负
    Math.max(); //取最大值
    Math.min(); //取最小值

    PASS:分割线 2017-05-0913:46:30

  • 相关阅读:
    java(一) 基础部分
    Spring使用Autowiring自动装配 解决提示报错小技巧
    idea 中dao层自动生成接口
    从git远程仓库Checkout项目到本地
    idea 新建项目上传至git(coding)
    使用Travis CI给hexo部署做持续集成
    LeetCode395-至少有 K 个重复字符的最长子串
    Java注解
    Java反射
    Java反射应用实例
  • 原文地址:https://www.cnblogs.com/zpzl/p/6690260.html
Copyright © 2011-2022 走看看