java内置核心语言对象
2016-04-16 15:03
561 查看
内置核心对象
object string array date Math
一:对象
二:数组
var arr=new Array(数组长度);
var arr=["","",""];
arr.sort();数组的排序
arr.join("-");链接
arr.push();在数组的最后一个位置添加,返回长度
arr.shift();在数组的第一个位置移除 返回该移除的元素
arr.pop();在数组的最后一个位置移除 返回该移除的元素
arr.unshift();在第一个位置添加;返回长度
Math.random();[0-1)
Math.floor( 数字 );//向下取整
Math.ceil( 数字 );//向上取整三
三:String
使用:
四:Math
Math.random() [0-1)
Math.floor( int ); 向下取整
Math.ceil( int ); 向上取整
Math.round( int ); 四舍五入
使用示例1:
var date=new Date();
date.getFullyear(); 获取年份
date.getMonth(); 月份是从0开始的
date.getDate();
date.getDay(); 星期,从星期天开始 0
使用实例:
object string array date Math
一:对象
<script> //对象的创建 //方法一: var people=new Object(); alert (people); //[object Object] alert (typeof(people)); //object alert ( people instanceof Object); //true :相当于people是继承与Object //方法二: var people =new Object; alert (people); //[object Object] alert (typeof(people)); //object alert ( people instanceof Object); //true :相当于people是继承与Object //方法三: var people ={ //键:值 name:"张三" } alert (people); //[object Object] alert (typeof(people)); //object alert ( people instanceof Object); //true :相当于people是继承与Object //方法四: var people = function(){ } //万物皆对象 var boy= new people(); alert (people); // function(){} alert (typeof(people)); //function alert ( people instanceof Object); //true :相当于boy是继承与Object //对象的使用 //一: var o=new Object; o.name="shuang"; o["sex"]="man"; alert ( o.name +" "+ o.sex );//shuang man //二 var o1={ name:'shuang', sex:'man' } for( var i in o1){ alert (i+":"+o1[i]); //name :shuang sex: man } alert(o1.hasOwnProperty("name"));//true </script>
二:数组
var arr=new Array(数组长度);
var arr=["","",""];
arr.sort();数组的排序
arr.join("-");链接
arr.push();在数组的最后一个位置添加,返回长度
arr.shift();在数组的第一个位置移除 返回该移除的元素
arr.pop();在数组的最后一个位置移除 返回该移除的元素
arr.unshift();在第一个位置添加;返回长度
Math.random();[0-1)
Math.floor( 数字 );//向下取整
Math.ceil( 数字 );//向上取整三
三:String
var str=new String() var str="";
使用:
var str=document.title; function line(){ str=str.substr(1,str.length)+str.substring(0,1);//substr:从1开始截取,截取str.length长度,不够就截取到最后一位;
<span style="white-space:pre"> </span>//substring:从0开始截取截取到1,包括0不包括1【0.1) document.title=str; console.log(str); } window.setInterval("line()",500);
四:Math
Math.random() [0-1)
Math.floor( int ); 向下取整
Math.ceil( int ); 向上取整
Math.round( int ); 四舍五入
使用示例1:
<script> var r,g,b; function color(){ r=parseInt(Math.random()*256-1); g=parseInt(Math.random()*256-1); b=parseInt(Math.random()*256-1); return "rgb("+r+","+g+","+b+")"; } function RandomColor(){ document.getElementById("s1").style.color=color(); document.getElementById("s2").style.color=color(); document.getElementById("s3").style.color=color(); } window.setInterval("RandomColor()",300); </script>五:date
var date=new Date();
date.getFullyear(); 获取年份
date.getMonth(); 月份是从0开始的
date.getDate();
date.getDay(); 星期,从星期天开始 0
使用实例:
<script> var arr=new Array(7); arr[0]="星期天"; arr[1]="星期一"; arr[2]="星期二"; arr[3]="星期三"; arr[4]="星期四"; arr[5]="星期五"; arr[6]="星期六"; function date(){ var date=new Date(); year=date.getFullYear(); month=date.getMonth()+1; dat=date.getDate(); day=date.getDay(); hour=date.getHours(); minu=date.getMinutes(); sec=date.getSeconds(); document.getElementById("a").innerHTML=year+"年"+month+"月"+dat+"日"+arr[day]+hour+":"+minu+":"+sec; } window.setInterval("date()",1000);//定时器,定时执行一个函数 </script>
相关文章推荐
- nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
- java的三大特性,封装,继承,多态
- Java:内省(Introspector)
- springMVC原理
- JVM8 元空间
- Spring事务配置常用的两种方法
- Java在mysql插入数据的时候的乱码问题解决
- 给自己的java程序生成API帮助文档
- springMVC学习之-------DispatcherServlet类
- JAVA 1.8 新特性学习(2) lambda表达式
- java 绘制一个全屏的三角形
- java web中路径问题。
- JavaWeb总结(八)—EL表达式
- Java 详解浅拷贝&&深拷贝
- Eclipse卸载安装的插件
- java之servlet
- Sprng MVC异常处理总结
- JAVA基础学习一些总结
- DL4J (DeepLearning for java)
- JAVA初学,对面向对象的一点理解