1。
//使用變數的屬性
<script type="text/網頁特效">
var txt="hello world!"
document.write(txt.length)
</script>
2。
//把字串中的所有字母都被轉化為大寫字母。
<script type="text/javascript">
var str="hello world!"
document.write(str.touppercase())
</script>
3。
//js中個變數添加超連結
<script type="text/javascript">
var txt="hello world!"
document.write("<p>超連結為: " + txt.link("http://www.w3school.com.cn") + "</p>")
</script>
4。
//indexof方法(定位字串中某一個指定的字元首次出現的位置。如果沒有查到返回-1,區分大小寫)
<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() 來尋找字串中特定的字元,並且如果找到的話,則返回這個字元。
<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>