JavaScript中Global、Math、Date對象的常用方法

來源:互聯網
上載者:User

標籤:log   alert   存在   www   執行   font   時間   decode   mat   

 

 

JavaScript當中Global、Math、Date類型常用方法如下:

 

 1 /* 2      js 中 Global對象 是一個不存在的對象,它裡面的方法可以調用 3      常用方法: 4      1 encodeURI 對uri進行轉換位元組, 不改變特殊符號,不常用 5      2 encodeURIComponent 對uri進行轉換位元組碼,符號全部轉換 常用 6      3 decodeURI  解碼 7      4 decodeURIComponent 解碼 8      5 eval  傳入一個字串,當作js指令碼進行執行 9      6 parseInt 字串轉換成整數10      7 parseFloat    字串轉成小數11      8 isNaN    不是number類型返回true 12      9 Escape     對帶有中文的字串轉碼   13      10 Unesacape    帶有中文的字串解碼14 */15 // 1 enCodeURI 對uri進行轉換位元組, 不改變特殊符號,不常用16 // 2 enCodeURIComponent 對uri進行轉換位元組碼,符號全部轉換 常用17 // 3 decodeURI  解碼18 // 4 decodeURIComponent 解碼    19 var uri = "http://www.baidu.com cn";20 var uri1 = encodeURI(uri);21 var uri2 = encodeURIComponent(uri);22 alert(uri1);23 alert(uri2);24 alert(decodeURI(uri1));25 alert(decodeURIComponent(uri2));26 27 28 //5 eval  傳入一個字串,當作js指令碼進行執行29 var str = "var a = 10;";30 eval(str);31 alert(a);32 var str1 = "{name:‘z3‘,age:18}";33 var obj = eval( "("+str1+")" );    //用括弧括起來 代表立即執行代碼塊,執行結果賦值給obj當作一個對象34 alert(obj.name);35 36 37  // 6 parseInt38  // 7 parseFloat39 alert(parseInt("10"));40 alert(parseFloat("10.1"));41 42 43 // 9 Escape 帶有中文的轉碼44 // 10 Unesacape    帶有中文的解碼45 var str = escape("哈哈");46 alert(str);47 alert(unescape(str));48 49 50 51 52 53 54 //Math.random() 產生[0,1)隨機數55 //Math.ceil(num) 向上取整56 //Math.floor(num) 向下取整57 //Math.round(num) 四捨五入58 59 60 61 var date = new Date();62 //alert(date);63 //Date日期 date = new Date()64 //擷取目前時間的方法65 var year = date.getFullYear();66 //alert(year);67 var month = date.getMonth() +1 ;68 //alert(month);69 var tdate = date.getDate(); //日期70 //alert(tdate);71 var hours = date.getHours();    //獲得小時72 //alert(hours);73 var min = date.getMinutes();    //分鐘74 //alert(min);75 var sec = date.getSeconds();    //秒76 //alert(sec);77 var day = date.getDay(); //星期幾78 //alert(day);79 80 //alert("今天是"+year+"年"+month+"月 "+day+"日,星期 "+day +","+ hours+"點"+min+"分"+sec+"秒 " );81 document.write("今天是"+year+"年"+month+"月 "+day+"日,星期 "+day +","+ hours+"點"+min+"分"+sec+"秒 " );82             

 

JavaScript中Global、Math、Date對象的常用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.