久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      javascript中是否有內(nèi)置對象

      javascript中有內(nèi)置對象。內(nèi)置對象是JS語言自帶的一些對象,常見的有:String對象、Array對象、Date對象、Boolean對象、Number對象、Math對象、RegExp對象、Global對象等等。

      javascript中是否有內(nèi)置對象

      本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

      JavaScript中的對象分為3中:自定義對象、內(nèi)置對象、瀏覽器對象

      前面兩種對象是JS基礎(chǔ)內(nèi)容,屬于ECMAScript;第三個瀏覽器對象屬于我們JS獨有的

      內(nèi)置對象就是指JS語言自帶的一些對象,這些對象供開發(fā)者使用,并提供了一些常用的或是最基本而必要的功能(屬性和方法)

      內(nèi)置對象最大的優(yōu)點就是幫助我們快速開發(fā)

      JavaScript提供了多個內(nèi)置對象,Math、Date、Array、String等

      • String對象:字符串對象,提供了對字符串進(jìn)行操作的屬性和方法。

      • Array對象:數(shù)組對象,提供了數(shù)組操作方面的屬性和方法。

      • Date對象:日期時間對象,可以獲取系統(tǒng)的日期時間信息。

      • Boolean對象:布爾對象,一個布爾變量就是一個布爾對象。(沒有可用的屬性和方法)

      • Number對象:數(shù)值對象。一個數(shù)值變量就是一個數(shù)值對象。

      • Math對象:數(shù)學(xué)對象,提供了數(shù)學(xué)運算方面的屬性和方法。

      • Object對象

      • RegExp對象

      • Global對象

      • Function對象

      • …..

      Math對象

      // Math數(shù)學(xué)對象 不是一個構(gòu)造函數(shù),所以我們不需要 new來調(diào)用 而是直接使用里面的屬性和方法即可         console.log(Math.PI); //一個屬性 圓周率         console.log(Math.max(1, 2, 99)); //99         console.log(Math.max(-1, -12)); //-1         console.log(Math.max(1, 99, '數(shù)學(xué)對象')); //NaN         console.log(Math.max()); //-Infinity

      案例:封裝自己的數(shù)學(xué)對象

      var myMath = {             PI: 3.141592653,             max: function() {                 var max = arguments[0];                 for (var i = 1; i < arguments.length; i++) {                     if (arguments[i] > max) {                         max = arguments[i];                     }                 }                 return max;             },             min: function() {                 var min = arguments[0];                 for (var i = 1; i < arguments.length; i++) {                     if (arguments[i] < min) {                         min = arguments[i];                     }                 }                 return min;             }         }         console.log(myMath.PI);         console.log(myMath.max(1, 5, 9));         console.log(myMath.min(1, 5, 9));

      1Math概述

      Math對象不是構(gòu)造函數(shù),它具有數(shù)學(xué)常數(shù)和函數(shù)的屬性和方法。跟數(shù)學(xué)相關(guān)的運行(求絕對值,取整,最大值等)可以使用Math中的成員。

      Math.PI                 //圓周率 Math.floor()           //向下取整 Math.ceil()            //向上取整 Math.round()           //四舍五入版  就近取整 注意-3,5  結(jié)果是 -3 Math.abs()             //絕對值 Math.max()/Math.min()  //求最大和最小值
      // 1.絕對值方法         console.log(Math.abs(1));    //1         console.log(Math.abs(-1));   //1         console.log(Math.abs('-1')); //隱式轉(zhuǎn)換 會把字符串型 -1 轉(zhuǎn)換為數(shù)字型         console.log(Math.abs('wode')); //NaN  // 2.三個取整方法 // (1)Math.floor()  地板 向下取整 往最小了取整         console.log(Math.floor(1.1));   //1         console.log(Math.floor(1.9));   //1 // (2)Math.ceil()   ceil 天花板 向上取整 往最大了取整         console.log(Math.ceil(1.1));   //2         console.log(Math.ceil(1.9));   //2 // (3)Math.round()   四舍五入  其他數(shù)字都是四舍五入,但是 .5特殊,它往大了取         console.log(Math.round(1.1));   //1         console.log(Math.round(1.5));   //2         console.log(Math.round(1.9));   //2         console.log(Math.round(-1.1));   //-1         console.log(Math.round(-1.5));   //這個結(jié)果是 -1

      2隨機(jī)數(shù)方法 random()

      //1. Math對象隨機(jī)數(shù)方法 random() 返回一個隨機(jī)的小數(shù)  0 =< x < 1 //2.這個方法里面不跟參數(shù) // 3.代碼驗證         console.log(Math.random()); // 4.我們想要得到兩個數(shù)之間的隨機(jī)整數(shù) 并且包含這兩個數(shù)         // return Math.floor(Math.random() * (max - min + 1)) + min;          function getRandom(min, max) {             return Math.floor(Math.random() * (max - min + 1)) + min;         }         console.log(getRandom(1, 10)); // 5.隨機(jī)點名         var arr = ['張三', '李四', '王五', '趙六', '張三瘋']             // console.log(arr[0]);             // console.log(arr[getRandom(0, 4)]);         console.log(arr[getRandom(0, arr.length - 1)]);

      案例:猜數(shù)字游戲

      程序隨機(jī)生成一個1~10之間的數(shù)字,并讓用戶輸入一個數(shù)字,

      1.如果大于該數(shù)字,就提示,數(shù)字大了,繼續(xù)猜;

      2.如果小于該數(shù)字,就提示,數(shù)字小了,繼續(xù)猜;

      3.如果等于該數(shù)字,就提示猜對了,結(jié)束程序。

      // 1.隨機(jī)生成一個1~10的整數(shù),我們需要用到Math.random()方法 // 2.需要一直猜到正確為止,所以一直循環(huán) // 3.用while循環(huán)合適更簡單 // 4.核心算法:使用if else if 多分支語句來判斷大于,小于,等于         function getRandom(min, max) {             return Math.floor(Math.random() * (max - min + 1)) + min;         }         var random = getRandom(1, 10);         while (true) { //死循環(huán)             var num = prompt('你來猜,輸入1~10之間的一個數(shù)字');             if (num > random) {                 alert('猜大了');             } else if (num < random) {                 alert('猜小了');             } else {                 alert('猜對了');                 break;             }         }
      // 要求用戶猜1~50之間的一個數(shù)字 但是只有10次猜的機(jī)會         function getRandom(min, max) {             return Math.floor(Math.random() * (max - min + 1)) + min;         }         var random = getRandom(1, 50);         var i = 0;         while (i < 10) { //死循環(huán)             var num = prompt('你來猜,輸入1~50之間的一個數(shù)字');             if (num > random) {                 alert('猜大了');             } else if (num < random) {                 alert('猜小了');             } else {                 alert('猜對了');                 break; //退出整個循環(huán)結(jié)束程序             }             i++;         }         if (i = 10) {             alert('全部猜錯了');         }

      日期對象

      1Date概述

      • Date對象和Math對象不一樣,他是一個構(gòu)造函數(shù),所以我們需要實例化后才能使用
      • Date實例用來處理日期和時間

      2Date()方法的使用

      1.獲取當(dāng)前時間必須實例化

      var now = new Date(); console.log(now);

      2.Date()構(gòu)造函數(shù)的參數(shù)

      如果括號里面有時間,就返回參數(shù)里面的時間,例如日期格式字符串為‘2019-5-1’,可以寫成new Date('2019-5-1')或者new Date('2019/5/1')

      //Date() 日期對象 是一個構(gòu)造函數(shù) 必須使用new 來調(diào)用創(chuàng)建我們的日期對象         var arr = new Date(); //創(chuàng)建一個數(shù)組對象         var obj = new Object(); //創(chuàng)建了一個對象實例 // 1.使用Date  如果沒有參數(shù) 返回當(dāng)前系統(tǒng)的當(dāng)前時間         var date = new Date();         console.log(date); // 2.參數(shù)常用的寫法 數(shù)字型 2019,10,01 或者是 字符串型 '2019-10-1 8:8:8'         var date1 = new Date(2019, 10, 1);         console.log(date1);  //返回的是 11月 不是 10月         var date2 = new Date('2019-10-1 8:8:8');         console.log(date2);

      3日期格式化

      我們想要2019-8-8 8:8:8格式的日期,要怎么辦?

      需要獲取日期指定的部分,所以我們要手動的得到這種格式

      方法名 說明 代碼
      getFullYears() 獲取當(dāng)年 dObj.getFullYears()
      getMonth() 獲取當(dāng)月(0-11) dObj.getMonth()
      getDate() 獲取當(dāng)天日期 dObj.getDate()
      getDay() 獲取星期幾(周日0 到周六6) dObj.getDay()
      getHours() 獲取當(dāng)前小時 dObj.getHours()
      getMinutes() 獲取當(dāng)前分鐘 dObj.getMinutes()
      getSeconds() 獲取當(dāng)前秒數(shù) dObj.getSeconds()
      // 格式化日期  年月日         var date = new Date();         console.log(date.getFullYear()); //返回當(dāng)前日期的年 2020         console.log(date.getMonth() + 1); //月份 返回的月份小1個月 記得月份 +1         console.log(date.getUTCDate()); //返回的是幾號         console.log(date.getDay()); //6 周一返回的是 1  周六返回的是 6 但是 周日返回的是 0 // 寫一個 2020年 5月 23日 星期六         var year = date.getFullYear();         var month = date.getMonth() + 1;         var dates = date.getDate();         var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];         var day = date.getDay();         console.log('今天是:' + year + '年' + month + '月' + dates + '日 ' + arr[day]);          // 格式化日期 時分秒         var date = new Date();         console.log(date.getHours()); //時         console.log(date.getMinutes()); //分         console.log(date.getSeconds()); //秒 // 要求封裝一個函數(shù)返回當(dāng)前的時分秒  格式是 08:08:08         function getTimer() {             var time = new Date();             var h = date.getHours();             h = h < 10 ? '0' + h : h;             var m = date.getMinutes();             m = m < 10 ? '0' + m : m;             var s = date.getSeconds();             s = s < 10 ? '0' + s : s;             return h + ':' + m + ':' + s;         }         console.log(getTimer());

      4獲取日期的總的毫秒形式

      Date對象是基于1970年1月1日(世界標(biāo)準(zhǔn)時間)起的毫秒數(shù)

      我們經(jīng)常利用總的毫秒數(shù)來計算時間,因為它更精確

      // 獲取Date總的毫秒數(shù)(時間戳) 不是當(dāng)前時間的毫秒數(shù) 而是距離1970年1月1日過了多少毫秒數(shù) // 1.通過 valueOf()   getTime()         var date = new Date();         console.log(date.valueOf()); //就是 我們現(xiàn)在時間 距離1970.1.1 總的毫秒數(shù)         console.log(date.getTime()); // 2.簡單的寫法(最常用的寫法)         var date1 = +new Date(); //+new Date() 返回的就是總的毫秒數(shù)         console.log(date1); // 3.H5 新增的 獲得總的毫秒數(shù)         console.log(Date.now());

      案例:倒計時效果

      // 倒計時效果 // 1.核心算法:輸入的時間減去現(xiàn)在的時間就是剩余的時間,即倒計時,但是不能拿著時分秒相減,比如05分減去25分,結(jié)果會是負(fù)數(shù)的 // 2.用時間戳來做,用戶輸入時間總的毫秒數(shù)減去現(xiàn)在時間的總的毫秒數(shù),得到的就是剩余時間的毫秒數(shù) // 3.把剩余時間總的毫秒數(shù)轉(zhuǎn)換為天、時、分、秒(時間戳轉(zhuǎn)換為時分秒) // 轉(zhuǎn)換公式如下: // d = parseInt(總秒數(shù) / 60 / 60 / 24); //計算天數(shù) // h = parseInt(總秒數(shù) / 60 / 60 % 24); //計算小時 // m = parseInt(總秒數(shù) / 60 % 60); //計算分?jǐn)?shù) // s = parseInt(總秒數(shù) % 60); //計算當(dāng)前秒數(shù)         function countDown(time) {             var nowTime = +new Date(); //返回的是當(dāng)前時間總的毫秒數(shù)             var inputTime = +new Date(time); //返回的是用戶輸入時間總的毫秒數(shù)             var times = (inputTime - nowTime) / 1000; //times是剩余時間總的秒數(shù)             var d = parseInt(times / 60 / 60 / 24); //天             d = d < 10 ? '0' + d : d;             var h = parseInt(times / 60 / 60 % 24); //小             h = h < 10 ? '0' + h : h;             var m = parseInt(times / 60 % 60); //分             m = m < 10 ? '0' + m : m;             var s = parseInt(times % 60); //當(dāng)前秒數(shù)             s = s < 10 ? '0' + s : s;             return d + '天' + h + '時' + m + '分' + s + '秒';         }         console.log(countDown('2020-5-24 00:00:00'));         var date = new Date();         console.log(date);

      數(shù)組對象

      1數(shù)組對象的創(chuàng)建

      創(chuàng)建數(shù)組對象的兩種方式

      • 字面量方式
      • new Array()
      // 創(chuàng)建數(shù)組的兩種方式 // 1.利用數(shù)組字面量         var arr = [1, 2, 3];         console.log(arr); // 2.利用new Array()         // var arr1 = new Array(); //創(chuàng)建了一個空的數(shù)組         // var arr1 = new Array(2); //這個2 表示 數(shù)組的長度為 2 里面有兩個空的數(shù)組元素         var arr1 = new Array(2, 3); //等價于[2,3] 這樣寫表示 里面有2個數(shù)組元素 是2和3         console.log(arr1);

      2檢測是否為數(shù)組

      // 翻轉(zhuǎn)數(shù)組         function reverse(arr) {             // if (arr instanceof Array) {             if (Array.isArray(arr)) {                 var newArr = [];                 for (var i = arr.length - 1; i >= 0; i--) {                     newArr[newArr.length] = arr[i];                 }                 return newArr;             } else {                 return 'error 這個參數(shù)要求必須是數(shù)組格式[1,2,3]'             }         }         console.log(reverse([1, 2, 3]));         console.log(reverse(1, 2, 3)); //[] // 檢測是否為數(shù)組 // (1)instanceof 運算符 它可以用來檢測是否為數(shù)組         var arr = [];         var obj = {};         console.log(arr instanceof Array);         console.log(obj instanceof Array); // (2)Array.isArray(參數(shù));  H5新增的方法 IE9以上版本支持         console.log(Array.isArray(arr));         console.log(Array.isArray(obj));

      3添加刪除數(shù)組元素的方法

        <p id="vfaef"><kbd id="vfaef"></kbd></p>

          方法名 說明 返回值
          push(參數(shù)1…) 末尾添加一個或多個元素,注意修改原數(shù)組 并返回新的長度
          pop()

          刪除數(shù)組最后一個元素,把數(shù)組長度減 1 無參數(shù),修改原數(shù)組

          返回它刪除的元素的值
          unshift(參數(shù)1…) 向數(shù)組的開頭添加一個或

          贊(0)
          分享到: 更多 (0)

          
          
          <pre id="vfaef"><u id="vfaef"></u></pre>

            <thead id="vfaef"><input id="vfaef"></input></thead>