返回字符串的长度 :
<html> <days> <script type = "text/javascript"> var txt = "hello world!" document.write (txt.length) </script> </body> </html>
为字符串添加样式 :
<html> <body> <script type = "text/javaScript"> var txt = "hello world!" document.write ("<p> besar:" + txt.big () + "</p>") document.write ("<p> Small:" + txt.small () + "</p>") document. "</p>") document.write ("<p> italic:" + txt.italics () + "</p>") document.write ("<p> Blink:" + txt.blink () + "(tidak berfungsi di </p>") document.write ("<p> fixed:" + txt.fixed () </p> ") document.write (" <p> fixed: " + txt.fixed () </p>") Document.write ("<p> fixed:" + txt.fixed () () () () + document.) txt.strike () + "</p>") document.write ("<p> fontcolor:" + txt.fontcolor ("merah") + "</p>") dokumen.write ("<p> FontSize:" + txt.fontsize (16) + "</p>") document. "</p>") document.write ("<p> huruf besar:" + txt.touppercase () + "</p>") document.write ("<p> Subscript:" + txt.sub () + "</p>") Document.write ("<p> SuperScript:" + txt.sup (): " txt.link ("http://www.w3school.com.cn") + "</p>") </cript> </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 ("scripl")) + </</> </") document.write (str.indexof (" scripl ")) + </br/") document.write (str.indexof ("")) + </br/") document.write (str.indexOf (" scripl ") </br/’ </qusrite ("scripl")效果如下 :
查找字符串中特定的字符 , 若找到 , 则返回该字符 - 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(atch.match"worll") + ") /> ") document.write (str.match (" world! ")) </script> </body> </html>效果如下 :
替换字符串中的字符 - ganti () :
<html> <day> <script type = "text/javaScript"> var str = "kunjungi microsoft!" document.write (str.replace (/microsoft/, "w3school")) </script> </body> </html>
效果如下 :
以上这篇 string javascript (字符串) 对象的简单实例 (推荐) 就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。