返回字符串的長度:
<html> <body> <script type =“ text/javascript”> var txt =“ hello world!”
為字符串添加樣式:
<html> <body> <script type =“ text/javascript”> var txt =“ hello world!” document.write(“ <p> big:” + txt.big() +“ </p>” “ </p>”)文檔。 txt.strike() +“ </p>”)document.write(“ <p> fontcolor:” + txt.fontcolor(“ red”) +“ </p>”)document.write.write(“ <p> fontsize:” + txt.fontsize(“ “ </p>”)document.write(“ <p> uppercase:” + txt.touppercase() +“ </p>”)document.write(“ <p> sisscript:” + txt.sub() + txt.sub() +“ </p>” txt.link(“ http://www.w3school.com.cn”) +“ </p>”)</script> </body> </body> </html>
返回字符串中指定文本首次出現的位置 -indexof()方法:
<html> <body> <script type =“ text/javascript”> var str =“ hello world!” document.write(str.indexof(“ hello”) +“ <br /> ")document.write(
效果如下:
查找字符串中特定的字符,若找到,則返回該字符 -match()方法:
<html> <body> <script type =“ text /javascript”> var str =“ hello world!” />“)document.write(str.match(“ world!”))</script> </body> </html>
效果如下:
替換字符串中的字符-替換():
<html> <body> <script type =“ text/javascript”> var str =“訪問microsoft!” document.write(str.replace(/microsoft/,“ w3school”)))</script> </script> </body> </html>
效果如下:
以上這篇javascript字符串(字符串)對象的簡單實例(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。 ,也希望大家多多支持武林網。