返回字符串的长度
<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>") document.write ("<p> pequeno:" + txt.small () + "</xt>") Document.ite ("<p> <p> (" + txt.small () + "</xt>"). "</p>") document.write ("<p> italic:" + txt.italics () + "</p>") document.write ("<p> pisca:" + txt.blink () + "(não funciona em ie) </p>") document.write ("<p> fixo:" + txt.fixed () "" txt.strike () + "</p>") document.write ("<p> fontcolor:" + txt.fontcolor ("vermelho") + "</p>") document.write ("<p> fontsize:" + txt.fontsize (16) + "</p>) "</p>") document.write ("<p> mancha:" + txt.TOUPERCASE () + "</p>") document.write ("<p> Subscrito:" + txt.sub () + "</p>") document.writes ("<p> SUPERSCRIBT:" + txt.sup () + " +" + " +" + "/P. txt.link ("http://www.w3school.com.cn") + "</p>") </script> </body> </html>返回字符串中指定文本首次出现的位置 - indexOf () 方法:
<html> <body> <script type = "text/javascript"> var str = "hello world!" Document.write (str.indexOF ("hello") + "<r />" )document.write(st.indexof("world") + "<br/>") document.write (stret.indexof (")效果如下
查找字符串中特定的字符 , 若找到 , 则返回该字符 - Match () 方法:
<html> <body> <script type = "text /javascript"> var str = "hello world!" Document.write (str.match ("mundial") + "<r />")document.write(str.match("world") + "<r /> "document.write(st.match("world") + " /> ") document.write (str.match (" mundo! ")) </script> </body> </html>效果如下
替换字符串中的字符 - Substitua ():
<html> <body> <script type = "text/javascript"> var str = "Visite Microsoft!" Document.Write (str.Replace (/Microsoft/, "W3School")) </script> </body> </html>
效果如下
String JavaScript String (字符串) 对象的简单实例 (推荐) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。