Javascript字符串對象的常用方法簡明版
更新時間:2014年06月26日 13:16:57 投稿:junjie
這篇文章主要介紹了Javascript字符串對象的常用方法簡明版,本文用一個代碼例子列表了Javascript字符串對象的一些常用方法,例如加粗、斜體、刪除線、上標(biāo)、下標(biāo)、大小寫、查找字符、替換字符等,需要的朋友可以參考下
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("上標(biāo):"+a.sup()+"<br />");
document.write("下標(biāo):"+a.sub()+"<br />");
document.write("大寫:"+a.toUpperCase()+"<br />");
document.write("大寫:"+a.toLowerCase()+"<br />");
document.write("返回索引字符:"+a.charAt(3)+"<br />");//這里應(yīng)該是"D"
document.write("返回索引:"+a.indexOf("f")+"<br />");//這里應(yīng)該是5
document.write("返回索引(逆向查找):"+a.lastIndexOf("f")+"<br />");//這里應(yīng)該是9
document.write("查找字符串:"+a.search("f")+"<br />");//這里應(yīng)該是5,與indexOf相同
document.write("替換字符串:"+a.replace("a","A")+"<br />");//把字符串中的a替換成A
document.write("返回子串:"+a.slice(1,3)+"<br />");//應(yīng)該是bc,返回從索引1到3-1的子串
document.write("分割字符串:"+a.split("D").toString()+"<br />");//把D作為分割符,分割字符串,返回?cái)?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 />");//正則匹配,返回匹配的結(jié)果,這里是32
相關(guān)文章
iframe 上下滾動條如何默認(rèn)在下方實(shí)現(xiàn)原理
iframe 上下滾動條如何默認(rèn)在下方,做的是聊天工具,數(shù)據(jù)多了,每次刷新出現(xiàn)的上下滾動默認(rèn)在上方,還需下拉到下面才能看到聊天記錄,本文將介紹,如和實(shí)現(xiàn)在下方2012-12-12
Javascript實(shí)現(xiàn)異步編程的過程
這篇內(nèi)容詳細(xì)分析了Javascript實(shí)現(xiàn)異步編程的過程以及原理解釋,對此知識點(diǎn)有興趣的朋友可以學(xué)習(xí)下。2018-06-06
解析JavaScript面向?qū)ο蟾拍钪械腛bject類型與作用域
這篇文章主要介紹了解析JavaScript面向?qū)ο蟾拍钪械囊妙愋团c作用域,文中重點(diǎn)講解了擴(kuò)充函數(shù)運(yùn)行作用域的需要的call和apply方法,朋友可以參考下2016-05-05

