Javascript字符串對象的常用方法簡明版
更新時間:2014年06月26日 13:16:57 投稿:junjie
這篇文章主要介紹了Javascript字符串對象的常用方法簡明版,本文用一個代碼例子列表了Javascript字符串對象的一些常用方法,例如加粗、斜體、刪除線、上標、下標、大小寫、查找字符、替換字符等,需要的朋友可以參考下
var a = "abcDEfGgdefg32asdf38"; document.write("原始:"+a+"<br />") document.write("粗體:"+a.bold()+"<br />"); document.write("大號:"+a.big()+"<br />"); document.write("斜體:"+a.italics()+"<br />"); document.write("刪除線:"+a.strike()+"<br />"); document.write("字體大小:"+a.fontsize(10)+"<br />"); document.write("字體顏色:"+a.fontcolor("#ff0000")+"<br />"); document.write("上標:"+a.sup()+"<br />"); document.write("下標:"+a.sub()+"<br />"); document.write("大寫:"+a.toUpperCase()+"<br />"); document.write("大寫:"+a.toLowerCase()+"<br />"); document.write("返回索引字符:"+a.charAt(3)+"<br />");//這里應該是"D" document.write("返回索引:"+a.indexOf("f")+"<br />");//這里應該是5 document.write("返回索引(逆向查找):"+a.lastIndexOf("f")+"<br />");//這里應該是9 document.write("查找字符串:"+a.search("f")+"<br />");//這里應該是5,與indexOf相同 document.write("替換字符串:"+a.replace("a","A")+"<br />");//把字符串中的a替換成A document.write("返回子串:"+a.slice(1,3)+"<br />");//應該是bc,返回從索引1到3-1的子串 document.write("分割字符串:"+a.split("D").toString()+"<br />");//把D作為分割符,分割字符串,返回數(shù)組 document.write("返回子串:"+a.substr(1,2)+"<br />");//返回子串,從索引1開始,長度為2,這里就是bc document.write("返回子串:"+a.substring(1,3)+"<br />");//與sclice()相同,返回索引1到3-1的子串 document.write("匹配:"+a.match(/\d+/)+"<br />");//正則匹配,返回匹配的結果,這里是32
相關文章
JavaScript中Number.NEGATIVE_INFINITY值的使用詳解
這篇文章主要介紹了JavaScript中Number.NEGATIVE_INFINITY值的使用,是JS入門學習中的基礎知識,需要的朋友可以參考下2015-06-06實例講解JavaScript中instanceof運算符的用法
JavaScript中的instanceof運算符可以用來判斷對象類型,而更重要的是instanceof能夠判斷對象的繼承關系,這里我們就來以實例講解JavaScript中instanceof運算符的用法2016-06-06JavaScript中的call方法和apply方法使用對比
這篇文章主要介紹了JavaScript中的call方法和apply方法使用對比,需要的朋友可以參考下2015-08-08