返回字符串的长度 :
<html> <body> <script type = "text/javaScript"> var txt = "¡Hello World!" Docum.Write (txt.length) </script> </body> </html>
为字符串添加样式 :
<html> <body> <script type = "text/javaScript"> var txt = "Hello World!" Document.Write ("<P> BIG:" + txt.big () + "</p>") document.write ("<p> pequeño:" + txt.small () + "</p>") document.write ("<P> negrita:" + txt.bold () "</p>") documento txt.strike () + "</p>") document.Write ("<P> fontColor:" + txt.FontColor ("rojo") + "</p>") document.write ("<p> fontSize:" + txt.FontSize (16) + "</p>") document.write ("<p> mimes:" + txt.tolower () +) "</p>") documento 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") + "<Br />")Document.Write(Str.indexof("World") + "<Br />") Document.Write (str.indexof ("World") </script> </body> </html>效果如下 :
查找字符串中特定的字符 , 若找到 则返回该字符 则返回该字符 - Match () 方法 :
<html> <body> <script type = "text /javaScript"> var str = "¡Hello World!" Document.Write (str.match ("World") + "<Br />")Document.Write(str.Match("World") + "<Br />")Document.Write(str.match(ceRLDLE") + "<Br />) /> ") document.write (str.match (" World! ")) </script> </body> </html>效果如下 :
替换字符串中的字符 - reemplazar () :
<html> <body> <script type = "text/javaScript"> var str = "Visite Microsoft!" Document.Write (str.replace (/Microsoft/, "W3School")) </script> </body> </html>
效果如下 :
以上这篇 Cadena JavaScript (字符串) 对象的简单实例 (推荐) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 也希望大家多多支持武林网。 也希望大家多多支持武林网。