javascript常用的內部類,javascript常用

來源:互聯網
上載者:User

javascript常用的內部類,javascript常用
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
</head>
<script type="text/javascript">
//javascript內部類,Number類
var num=new Number(12.3456);
document.write(num.toFixed(2));
document.write("<br>"+Number.MIN_VALUE);
//javascript內部類,Math類
var ma=90.1;
//向下取整
document.write("<br>"+Math.floor(49.5));
//向上取整
document.write("<br>"+Math.ceil(13.2));
document.write("<br>"+Math.random(Math.random()*100));
//javascript內部類,Date類
var mydate=new Date();
document.write("<br>"+mydate.toLocaleString());
document.write("<br>"+(mydate.getMonth()+1));
//javascript內部類,String類
var txt="h韓llo中國";
document.write("<br>"+txt.indexOf("worldr"));
var arr=txt.split("");
document.write(arr);
var sub=txt.substr(3,3);
var sub=txt.substring(0,2);
var sub=txt.charAt(3);
//javascript內部類,Array類
arr[0]=12;
arr[1]="hello";
arr[2]="China";
//刪除第2個元素->下標為1
//第一個1 表示刪除第幾個元素, 第二個1表示刪除1個
arr.splice(1,1);
//修改第二個 "hello"-> "world"
//更新
arr.splice(1,1,"world");
//把一個新的資料"北京",添加到第1元素後面
arr.splice(1,0,"北京");
for(var key in arr){
document.write(arr[key]+"<br>");
}
</script>
<body>
</body>

</html>

這幾個類很重要,要多多看手冊才行,這裡寫的都是常見的用法。

著作權聲明:博主原創文章,轉載請說明出處。http://blog.csdn.net/dzy21

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.