Js中String类型方法用法大全

来源:互联网 发布:iframe 端口不同 跨域 编辑:程序博客网 时间:2024/06/05 06:43
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title></head><body><script>var str="Hello World!";document.write("源字符串:"+str+"<br />")/* * 1、计算字符串的长度,输出结果12 * 2、字符串加粗加黑 * 3、字符串变小 * 4、字符串加粗 * 5、字符串变颜色 * 6、字符串设置大小(1~7) * 7、字符串转大写 * 8、字符串转小写 * 9、上标显示 * 10、下表显示 * 11、加删除线 * 12、加超级连接 * 13、indexOf()用法,当字符串存在,返回第一次出现位置下标 * 14、当字符串不存在,返回-1 * 15、lastIndexOf用法,返回最后一次出现字符串的下标 * 16、match用法,区分大小写,存在则返回,不存在则返回null * 17、字符串替换,replace(),只替换出现的第一个字符,如果全部替换可使用正则表达式 * 18、charAt(),返回数组下标的字母 * 19、concat(),连接字符串 * 20、fromCharCode(),根据字符编码创建一个字符串 * 21、字符串变为斜体 */document.write("1、"+str.length+"<br />");document.write("2、"+str.big()+"<br />")document.write("3、"+str.small()+"<br />")document.write("4、"+str.bold()+"<br />")document.write("5、"+str.fontcolor("Red")+"<br />")document.write("6、"+str.fontsize(7)+"<br />")document.write("7、"+str.toUpperCase()+"<br />")document.write("8、"+str.toLowerCase()+"<br />")document.write("9、"+str+str.sub()+"<br />")document.write("10、"+str+str.sup()+"<br />")document.write("11、"+str.strike()+"<br />")document.write("12、"+str.link("https:\\www.baidu.com")+"<br />")document.write("13、"+str.indexOf("ell")+"<br />")document.write("14、"+str.indexOf("AAA")+"<br />")document.write("15、"+str.lastIndexOf("l")+"<br />")document.write("16、"+str.match("World")+"<br />")document.write("17、"+str.replace("l","*")+"<br />")document.write("18、"+str.charAt(3)+"<br />")document.write("19、"+str.concat("ABC")+"<br />")document.write("20、"+String.fromCharCode(67,68,69)+"<br />")document.write("21、"+str.italics()+"<br />")</script></body></html>

运行结果如下所示:


原创粉丝点击