標籤:
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.結果:
3.
javascript 基礎2第12節