欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

菜鳥javascript基礎(chǔ)資料整理2

 更新時(shí)間:2010年12月06日 20:32:34   作者:  
JavaScript 對象,這里涉及到變量與數(shù)組等的使用。
1。
//使用變量的屬性
<script type="text/javascript">
var txt="Hello World!"
document.write(txt.length)
</script>


2。
//把字符串中的所有字母都被轉(zhuǎn)化為大寫字母。
<script type="text/javascript">
var str="Hello world!"
document.write(str.toUpperCase())
</script>


3。
//js中個(gè)變量添加超鏈接
<script type="text/javascript">
var txt="Hello World!"
document.write("<p>超鏈接為: " + txt.link("http://www.w3school.com.cn") + "</p>")
</script>

4。
//indexOf方法(定位字符串中某一個(gè)指定的字符首次出現(xiàn)的位置。如果沒有查到返回-1,區(qū)分大小寫)
<script type="text/javascript">
var str="Hello world!"
document.write(str.indexOf("Hello") + "<br />") //1
document.write(str.indexOf("World") + "<br />") //-1
document.write(str.indexOf("world")) //6
</script>

5。
//match() 方法
//使用 match() 來查找字符串中特定的字符,并且如果找到的話,則返回這個(gè)字符。
<script type="text/javascript">
var str="Hello world!"
document.write(str.match("world") + "<br />") //world
document.write(str.match("World") + "<br />") //null
document.write(str.match("worlld") + "<br />") //null
document.write(str.match("world!")) //world!
</script>


6。
//replace() 方法在字符串中用某些字符替換另一些字符。
var str="Visit Microsoft!"
document.write(str.replace("Microsoft","W3School"))


7.
//合并兩個(gè)數(shù)組
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr2 = new Array(3)
arr2[0] = "James"
arr2[1] = "Adrew"
arr2[2] = "Martin"
document.write(arr.concat(arr2))
</script>

相關(guān)文章

最新評論