javascript 基础2第12节

时间:2024-01-04 14:06:50

1.

<html>
<head>
<title>javascript基础</title>
</head> <body> 1.Number</br>
<script type="text/javascript">
var ia = 10;//基本类型 typeof
var name = '张三';
var married = false; var oNum = new Number(10);
var oName = new String('张三'); document.write("typeof ia : " ,typeof ia,"<br/>"); document.write("typeof name : " ,typeof name,"<br/>");
document.write("name.toString() : " , name.toString(),"<br/>");//伪对象 document.write("typeof oName : " ,typeof oName,"<br/>");
document.write("typeof oNum : " ,typeof oNum,"<br/>");
//对象类型检测 instanceof
document.write("oNum instanceof Number : " , oNum instanceof Number,"<br/>");
document.write("ia == oNum : " ,ia == oNum,"<br/>");
document.write("ia === oNum : " ,ia === oNum,"<br/>"); var ob = Number('123');//基本类型
document.write("typeof ob : " ,typeof ob,"<br/>");
document.write("ob : " , ob,"<br/>");
document.write("Number.MAX_VALUE : " , Number.MAX_VALUE,"<br/>");
document.write("Number.MIN_VALUE : " , Number.MIN_VALUE,"<br/>"); var ib = 3.148592654233789; //new Number();
document.write("ib : " , ib,"<br/>");
document.write("ib.toFixed(2) : " , ib.toFixed(2),"<br/>");
</script>
2.Boolean</br>
<script type="text/javascript"> document.write("Boolean(5) : " , Boolean(5),"<br/>");
document.write("Boolean(null) : " , Boolean(null),"<br/>");
document.write("Boolean('a') : " , Boolean('a'),"<br/>");
</script> 3.String</br>
<script type="text/javascript">
var str = "Hello World Hello JavaScript I like jaVAScript you like JAVAscript";
document.write("str : " , str,"<br/>");
document.write("str属性length : " , str.length,"<br/>");
document.write("str.toUpperCase() : " , str.toUpperCase(),"<br/>");
document.write("str.toLowerCase() : " , str.toLowerCase(),"<br/>");
document.write("str.charAt(0) : " , str.charAt(0),"<br/>");
document.write("str.charAt(X) : " , str.charAt(str.length-1),"<br/>"); document.write("str.charCodeAt(19) : " , str.charCodeAt(19),"<br/>");
document.write("str.concat(10,'abcd',true) : " , str.concat(10,'abcd',true),"<br/>");
document.write("String.fromCharCode(97) : " , String.fromCharCode(97),"<br/>");
//查找
document.write("str.indexof('java') : " , str.indexOf('java'),"<br/>");
document.write("str.indexof('java') : " , str.toLowerCase().indexOf('java'),"<br/>"); document.write("str.indexof('java',20) : " , str.toLowerCase().indexOf('java', 20),"<br/>"); document.write("str.lastIndexof('java') : " , str.toLowerCase().lastIndexOf('java'),"<br/>");
//截取
document.write("str.slice(6,11) : " , str.slice(6,11),"<br/>");
document.write("str.substr(6,5) : " , str.substr(6,5),"<br/>");
document.write("str.substring(6) : " , str.substring(6),"<br/>");
var data = "2014-7-28";
var arr = data.split('-');//字符串数组
document.write("arr[0] : " , arr[0],"<br/>");
document.write("arr[1] : " , arr[1],"<br/>");
document.write("arr[2] : " , arr[2],"<br/>");
</script>
</body> </html>

2.结果:

javascript 基础2第12节

3.

javascript 基础2第12节