1 所有JavaScript數字均為64位,整數(不使用小數點或指數計數法)最多為15位。
2 絕不要在數字前面寫零或x,除非需要進行進制轉換(0表示八進制,x為十六進制)。
3 JavaScript String(字符串)對象 實例
(1) 計算字符串的長度? ??
var txt="Hello World!"??
document.write(txt.length)
(2)為字符串添加樣式
<body>
<script type = "text/javascript">
var txt="Hello World!"
document.write("Big: " + txt.big() + "")
document.write("Small: " + txt.small() + "")
document.write("Bold: " + txt.bold() + "")
document.write("Italic: " + txt.italics() + "")//斜體
document.write("Blink: " + txt.blink() + " (does not work in IE)")
document.write("Fixed: " + txt.fixed() + "")
document.write("Strike: " + txt.strike() + "")//刪除線
document.write("Fontcolor: " + txt.fontcolor("Red") + "")
document.write("Fontsize: " + txt.fontsize(16) + "")
document.write("Lowercase: " + txt.toLowerCase() + "")
document.write("Uppercase: " + txt.toUpperCase() + "")
document.write("Subscript: " + txt.sub() + "")//Subscript: Hello World!
document.write("Superscript: " + txt.sup() + "")//Superscript: Hello World!
document.write("Link: " + txt.link("http://www.w3school.com.cn") + "")//鏈接
</script>
</body>
4 indexOf()方法,用于定位字符串中某一個指定的字符首次出現的位置
<body>
<script type = "text/javascript">
var str="Hello world!"
document.write(str.indexOf("Hello") + "")
document.write(str.indexOf("World") + "")
document.write(str.indexOf("world"))
</script>
</body>
查看結果:
0
-1
6
5 match()方法,查找字符串中特定的字符,并且如果找到的話,則返回這個字符。
<body>
<script type = "text/javascript">
var str="Hello world!"
document.write(str.match("world") + "")
document.write(str.match("World") + "")
document.write(str.match("worlld") + "")
document.write(str.match("world!"))
</script>
</body>
查看結果
world
null
null
world!
6 替換字符串replace()方法,用于在字符串中用某些字符替換另一些字符
<body>
<script type = "text/javascript">
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))
</script>
</body>
查看結果
Visit W3School!
7 日期對象用于處理日期和時間
