最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript String(字符串)對象的簡單實例(推薦)

 更新時間:2016年08月31日 10:45:38   投稿:jingxian  
下面小編就為大家?guī)硪黄狫avaScript String(字符串)對象的簡單實例(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

返回字符串的長度:

<html>
<body>

<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>Big: " + txt.big() + "</p>")
document.write("<p>Small: " + txt.small() + "</p>")

document.write("<p>Bold: " + txt.bold() + "</p>")
document.write("<p>Italic: " + txt.italics() + "</p>")

document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>")
document.write("<p>Fixed: " + txt.fixed() + "</p>")
document.write("<p>Strike: " + txt.strike() + "</p>")

document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")

document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")

document.write("<p>Subscript: " + txt.sub() + "</p>")
document.write("<p>Superscript: " + txt.sup() + "</p>")

document.write("<p>Link: " + txt.link("http://www.w3school.com.cn") + "</p>")
</script>

</body>
</html>

返回字符串中指定文本首次出現(xiàn)的位置 - 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("worlld") + "<br />")
document.write(str.match("world!"))

</script>

</body>
</html>

效果如下:

 

替換字符串中的字符 - replace():

<html>
<body>

<script type="text/javascript">

var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))

</script>
</body>
</html>

效果如下:

以上這篇JavaScript String(字符串)對象的簡單實例(推薦)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

陆良县| 黔东| 福安市| 德钦县| 和顺县| 宁城县| 丰台区| 章丘市| 泰宁县| 平度市| 徐水县| 石河子市| 化隆| 牟定县| 修水县| 萨迦县| 漳浦县| 望都县| 浪卡子县| 永川市| 高雄县| 龙里县| 泰兴市| 武隆县| 东平县| 成都市| 凯里市| 江山市| 秦皇岛市| 上蔡县| 射洪县| 林芝县| 鹿邑县| 景宁| 凤城市| 汪清县| 略阳县| 石楼县| 城固县| 永康市| 绵阳市|