笔记:js内置对象及自定义对象
来源:互联网 发布:js 字符串转对象 编辑:程序博客网 时间:2024/05/16 23:02
--------------------------内置对象
String
Math
Date
Array
Event
------------String
str.length;
str.charAt(5);
str.indexOf(""); //找不到返回-1
str.toLowerCase();
str.toUpperCase();
str.subString(3,6);
str.replace("","");
-------------math
Math.PI
Math.LN2
Math.LOG2E
Math.SQRT2
Math.max(..,..);
Math.min(..,..);
Math.round(...); //对参数四舍五入
Math.floor(..); //取不大于参数的整数
Math.ceil(..); //取不小于参数的整数
Math.random(); //生成0-1的随机数
--------------Date
Date对象三种方法
1.从系统中获取当前的时间和日期
<script language="javascript">var now=new Date();document.write(now.getYear()+ "年" + (now.getMonth() + 1) + "月" + now.getDate()+ "日" + now.getHours()+ ":" + now.getMinutes() + ":" + now.getSeconds());</script>
月用0-11表示,因此应加1
2.设置当前时间和日期
<script language="javascript">var now=new Date();now.setMonth(10);now.setDate(23);document.write(now.getYear() + "--" + (now.getMonth() + 1) + "--" + now.getDate());</script>
3.时间,日期转换成其他格式
<script language="javascript">var now=new Date();now.setMonth(10);now.setDate(23);document.write(now.getYear() + "--" + (now.getMonth() + 1) + "--" + now.getDate() + "<br>");document.write(now.toGMTString() + "<br>");//返回GMT格式时间document.write(now.toLocaleString() + "<br>");//返回本地时间</script>
结果显示:
2012--11--23
Fri, 23 Nov 2012 12:47:22 UTC
2012年11月23日星期五 20:47:22
-------------Array
<script language="javascript">var a= new Array(3);a[0]=1;a[1]=4;a[2]=2;for(i=0; i<3; i++) {document.write("a[" + i + "]:" + a[i] + "<br />");}document.write("<br>");a.sort();//以ascii代码来排列先后顺序for(i=0; i<3; i++) {document.write("a[" + i + "]:" + a[i] + "<br />");}document.write("<br>");a.reverse();//数组内元素倒置for(i=0; i<3; i++) {document.write("a[" + i + "]:" + a[i] + "<br />");}document.write("<br>" + a.join());//数组内元素弄成字符串插入页面</script>
-----------------自定义对象
<script language="javascript">function printColor() {document.write("color is:" + this.color + "<br>");}function printSize() {document.write("size is:" + this.size + "<br>");}function app(tcolor, tsize) {this.color=tcolor;this.size=tsize;this.pcolor=printColor;//定义对象的pcolor方法this.psize=printSize;}var app1 = new app("green", 10);var app2 = new app("magenta", 20);app1.pcolor();app1.psize();app2.pcolor();app2.psize();</script>
- 笔记:js内置对象及自定义对象
- js内置对象 学习笔记
- 【JS学习笔记】内置对象
- js笔记4内置对象
- js内置对象 学习笔记
- js内置对象方法笔记 js内置函数
- JS内置对象属性及方法大全
- js内置对象属性及方法
- js的常用函数,自定义对象,内置对象
- javascript学习笔记--js内置对象
- JS学习笔记(5)内置对象
- JS 自定义对象及 属性
- js的内置对象
- js常用内置对象
- js内置对象
- js 内置对象
- js内置对象
- JS内置对象
- linux下tar压缩使用
- 一片牧草,草每天生长的速度相同,这片牧草可供27头牛吃6天,可供46只羊吃9天,如果一头牛的吃草量等于2只羊的吃草量,那么11头牛和20只羊一起吃可以吃多少天?
- MSSQL笔记七
- DX9、XP游戏和更多3D绘图 - OpenGL - 还有未来吗?
- 57 wpf 椭圆圈圈
- 笔记:js内置对象及自定义对象
- FPGA_TPMS_10_12
- 硬件加速的选择OpenGL、DirectX
- UITextField中复制和粘贴为中文
- linux去掉蜂鸣声
- C#中的快捷键,可以更方便的编写代码
- Image Classification——Sparse Code
- 谈谈两个奇葩公司
- 数据库连接池,在tomcat中配置数据源: