Javascript字符串对象的常用方法简明版
更新时间:2014年06月26日 13:16:57 投稿:junjie
这篇文章主要介绍了Javascript字符串对象的常用方法简明版,本文用一个代码例子列表了Javascript字符串对象的一些常用方法,例如加粗、斜体、删除线、上标、下标、大小写、查找字符、替换字符等,需要的朋友可以参考下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
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作为分割符,分割字符串,返回数组 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 数据类型转换(parseInt,parseFloat)
Number、String函数是特殊的函数,在JS引擎中,他会自动判断是作为构造函数调用还是普通调用,所以既可以使用new关键字,也可以作为函数直接调用。2010-07-07javascript中call,apply,bind的用法对比分析
这篇文章主要给大家对比分析了javascript中call,apply,bind三个函数的用法,非常的详细,这里推荐给小伙伴们。2015-02-02详解JavaScript中的数据类型,以及检测数据类型的方法
这篇文章主要介绍了JavaScript中的数据类型,以及检测数据类型的方法,帮助大家巩固基础知识,感兴趣的朋友可以了解下2020-09-09
最新评论