zoukankan      html  css  js  c++  java
  • js中常见的内置对象

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">

    function testDate(){
    /**
    * 测试Date对象
    */
    var date = new Date();
    console.log(date.getFullYear());
    console.log(date.getYear());
    console.log(date.getMonth());
    console.log(date.getDay());
    console.log(date.getDate());
    console.log(date.getHours());
    console.log(date.getMinutes());
    console.log(date.getSeconds());
    console.log(date.getMilliseconds());
    }

    function testString(){
    var s = "this is a STRING test";
    //穿件一个锚点 <a name="is">this is a string test</a>
    //document.write(s.anchor("is"));
    console.log(s.anchor("is"));
    console.log(s.charAt(2));
    console.log(s[2]);
    console.log(s.charCodeAt(2));

    console.log(s.concat(",this","is "));
    //返回的是 第一个与它匹配的字符串的位置
    console.log(s.indexOf("is",8)) //第二个参数 表示 查找的其实位置

    console.log(s.replace("is",function (){
    return "tttt"; //用函数处理 返回值
    }));

    console.log(s.substr(1,2)); //长度 包含末尾
    console.log(s.substring(1,2)); //位置 不包含末尾

    console.log(s.toLowerCase());
    console.log(s.toUpperCase());

    //字符串可以当作数组使用
    s[2] = "tttt";
    console.log(s);

    for(var i in s){
    console.log(s[i]);
    }
    }

    function testMath(){
    console.log(Math.abs("-10"));
    console.log(Math.ceil(-1.2));
    console.log(Math.floor(-1.2));

    console.log(Math.max(1,2,.43,123,21,3,1,4,2,5,7,8));

    console.log(Math.min(1,2,.43,123,21,3,1,4,2,5,7,8))

    //在计算金融的时候 一定要适当的将大单位换成小单位计算
    var n1 = 0.2-0.1;
    var n2 = 0.3-0.2;
    console.log(n1===n2);

    }

    </script>
    </head>
    <body>
    <input type="button" onclick="testDate()" value="date">
    <input type="button" onclick="testString()" value="string">
    <input type="button" onclick="testMath()" value="math">
    </body>
    </html>
  • 相关阅读:
    bzoj 4012: [HNOI2015]开店
    POJ 1054 The Troublesome Frog
    POJ 3171 Cleaning Shifts
    POJ 3411 Paid Roads
    POJ 3045 Cow Acrobats
    POJ 1742 Coins
    POJ 3181 Dollar Dayz
    POJ 3040 Allowance
    POJ 3666 Making the Grade
    洛谷 P3657 [USACO17FEB]Why Did the Cow Cross the Road II P
  • 原文地址:https://www.cnblogs.com/hwgok/p/5723012.html
Copyright © 2011-2022 走看看