JavaScript -- 知识点回顾篇(三):js中的 String 对象的方法

(1) anchor(): 创建 HTML 锚。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.anchor("mytxt1"))
</script>

  

(2) big(): 用大号字体显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.big());
</script>

  

(3) blink(): 显示闪动字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.blink());
</script>

  

(4) bold(): 使用粗体显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.bold());
</script>

  

(5) charAt() 返回在指定位置的字符。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.charAt(0));
</script>

(6) charCodeAt(): 返回在指定的位置的字符的 Unicode 编码。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.charCodeAt(0));
</script>

(7) concat(): 连接字符串。

      <script type="text/javascript">
var txt1="Hello world!"
var txt2=" 2018 "
document.write(txt1.concat(txt2));
</script>

(8) fixed(): 以打字机文本显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.fixed());
</script>

  

(9) fontcolor(): 使用指定的颜色来显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.fontcolor("Red"));
</script>

  

(10) fontsize(): 使用指定的尺寸来显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.fontsize(7));
</script>

  

(11) fromCharCode(): 从字符编码创建一个字符串。

      <script type="text/javascript">
document.write(String.fromCharCode(65,66,67,68,69));
</script>

  

(12) indexOf(): 检索字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.indexOf('w'));
</script>

  

(13) italics(): 使用斜体显示字符串。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.italics());
</script>

  

(14) lastIndexOf():    从后向前搜索字符串。如果要检索的字符串值没有出现,则该方法返回 -1。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.lastIndexOf('e'));
document.write('<br/>');
document.write(txt1.lastIndexOf('world'));
document.write('<br/>');
document.write(txt1.lastIndexOf('x'));
</script>

  

(15) link(): 将字符串显示为链接。

      <script type="text/javascript">
var txt1="Hello world!"
document.write(txt1.link("https://www.cnblogs.com"));
</script>

  

(16) localeCompare(): 用本地特定的顺序来比较两个字符串。大于返回1,小于返回-1,等于返回0。

      <script type="text/javascript">
var txt1='Hello world2019!'
var txt2='Hello world2018!';
var txt3='Hello world2018!';
document.write(txt1.localeCompare(txt2));
document.write('<br/>');
document.write(txt2.localeCompare(txt1));
document.write('<br/>');
document.write(txt2.localeCompare(txt3));
</script>

  

(17) match(): 找到一个或多个正则表达式的匹配。

      <script type="text/javascript">
var txt1='Hello world2019and2020!'
document.write(txt1.match('Hello'));
document.write('<br/>');
document.write(txt1.match('xyz'));
document.write('<br/>');
document.write(txt1.match(/\d+/g));
</script>

  

(18) replace(): 替换与正则表达式匹配的子串。

      <script type="text/javascript">
var txt1='Hello world2019and2020!'
document.write(txt1.replace(/world/g, "My Baby"));
</script>

  

(19) search(): 检索与正则表达式相匹配的值。

      <script type="text/javascript">
var txt1='Hello world2019and2020!'
document.write(txt1.search(/world/));
</script>

  

(20) slice(): 提取字符串的片断,并在新的字符串中返回被提取的部分。

      <script type="text/javascript">
var txt1='Hello world2019and2020!'
document.write(txt1.slice(11));
</script>

  

(21) small(): 使用小字号来显示字符串。

      <script type="text/javascript">
var txt1='Hello World2019and2020!'
document.write(txt1.small());
</script>

  

(22) split(): 把字符串分割为字符串数组。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!'
document.write(txt1.split(" "));
</script>

  

(23) strike(): 使用删除线来显示字符串。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!'
document.write(txt1.strike());
</script>

  

(24) sub():  把字符串显示为下标。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!'
var txt2='xxx';
document.write(txt1+txt2.sub());
</script>

  

(25) substr(): 从起始索引号提取字符串中指定数目的字符。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!'
document.write(txt1.substr(3,11));
</script>

  

(26) substring(): 提取字符串中两个指定的索引号之间的字符。与 slice() 和 substr() 方法不同的是,substring() 不接受负的参数。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!'
document.write(txt1.substring(3,12));
</script>

  

(27) sup():  把字符串显示为上标。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!';
var txt2='ppp';
document.write(txt1+txt2.sup());
</script>

  

(28) toLocaleLowerCase(): 把字符串转换为小写。

  与 toLowerCase() 不同的是,toLocaleLowerCase() 方法按照本地方式把字符串转换为小写。

  只有几种语言(如土耳其语)具有地方特有的大小写映射,所有该方法的返回值通常与 toLowerCase() 一样。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!';
document.write(txt1.toLocaleLowerCase());
</script>

  

(29) toLocaleUpperCase(): 把字符串转换为大写。

  与 toUpperCase() 不同的是,toLocaleUpperCase() 方法按照本地方式把字符串转换为大写。

  只有几种语言(如土耳其语)具有地方特有的大小写映射,所有该方法的返回值通常与 toUpperCase() 一样。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!';
document.write(txt1.toLocaleUpperCase());
</script>

  

(30) toLowerCase():   把字符串转换为小写。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!';
document.write(txt1.toLowerCase());
</script>

  

(31) toUpperCase():   把字符串转换为大写。

      <script type="text/javascript">
var txt1='Hello World 2019 and 2020!';
document.write(txt1.toUpperCase());
</script>

  

JavaScript -- 时光流逝(三):js中的 String 对象的方法的更多相关文章

  1. JavaScript -- 时光流逝(五):js中的 Date 对象的方法

    JavaScript -- 知识点回顾篇(五):js中的 Date 对象的方法 Date 对象: 用于处理日期和时间. 1. Date对象的方法 <script type="text/ ...

  2. JavaScript中的string对象及方法

    string对象 string对象的两种创建 var a="hello"; var b=new String("hello"); //下面是方法 //charA ...

  3. JavaScript -- 时光流逝(十):Screen 对象、History 对象、Location 对象

    JavaScript -- 知识点回顾篇(十):Screen 对象.History 对象.Location 对象 1. Screen 对象 1.1 Screen 对象的属性 (1) availHeig ...

  4. JavaScript -- 时光流逝(九):Window 对象、Navigator 对象

    JavaScript -- 知识点回顾篇(九):Window 对象.Navigator 对象 1. Window 对象 1.1 Window 对象的属性 (1) closed: 返回窗口是否已被关闭. ...

  5. js中获取事件对象的方法小结

    原文地址:http://jingyan.baidu.com/article/d8072ac4594d6cec95cefdac.html 事件对象 的获取很简单,很久前我们就知道IE中事件对象是作为全局 ...

  6. js中的数组对象排序(方法sort()详细介绍)

    定义和用法 sort() 方法用于对数组的元素进行排序. 语法    arrayObject.sort(sortby) 参数sortby:可选.规定排序顺序.必须是函数. 返回值 对数组的引用.请注意 ...

  7. js中数组Array对象的方法sort()的应用

    一. sort()方法的介绍 //给一组数据排序 var arrNum = [12,1,9,23,56,100,88,66]; console.log("排序前的数组:"+arrN ...

  8. JS中创建自定义对象的方法

    1.直接给对象扩充属性和方法: 2.对象字面量: 3.工厂方式: 4.构造函数方式: 5.原型方式: 6.混合方式. <script> // 1.直接给对象扩充属性和方法; var cat ...

  9. JavaScript -- 时光流逝(四):js中的 Math 对象的属性和方法

    JavaScript -- 知识点回顾篇(四):js中的 Math 对象的属性和方法 1. Math 对象的属性 (1) E :返回算术常量 e,即自然对数的底数(约等于2.718). (2) LN2 ...

随机推荐

  1. Java设计模式学习记录-观察者模式

    前言 观察者模式也是对象行为模式的一种,又叫做发表-订阅(Publish/Subscribe)模式.模型-视图(Model/View)模式. 咱们目前用的最多的就是各种MQ(Message Queue ...

  2. 绝对路径的表示方式为什么是"/usr"而不是"//usr"

    今天闲逛贴吧,竟然看到有个人问绝对路径的表示方式为什么不是//usr/local而是/usr/local.原文: 我想99%的人都没想过这个问题,都理所当然的认为:它不就是根"/" ...

  3. 跨域学习笔记3--web.config设置之system.webServer 详细介绍,为网站设置默认文档

    自己并不懂,在此先记录下来,留待以后学习... 如何:为 IIS 7.0 配置 <system.webServer> 节2008-06-14 22:26http://technet.mic ...

  4. [转]Build An Image Manager With NativeScript, Node.js, And The Minio Object Storage Cloud

    本文转自:https://www.thepolyglotdeveloper.com/2017/04/build-image-manager-nativescript-node-js-minio-obj ...

  5. 【Java每日一题】20170213

    20170210问题解析请点击今日问题下方的“[Java每日一题]20170213”查看(问题解析在公众号首发,公众号ID:weknow619) package Feb2017; public cla ...

  6. (4)Microsoft office Word 2013版本操作入门_插入图片及图片的排版

    1.word中插入图片和文绕图 1.1插入图片 :点击[插入]-->[图片] 或者 [联机图片]从网上选择. 1.2文字环绕: [格式] --->点击[位置]   .[自动换行]  进行图 ...

  7. 如何处理Express异常?

    译者按:根据墨菲定律:“有可能出错的事情,就会出错”.那么,既然代码必然会出错,我们就应该处理好异常. 原文: How to handle errors in Express 译者:Fundebug ...

  8. linux查看用户、创建用户、设置密码、修改用户、删除用户命令

    查看用户 /etc/passwd /etc/shadow id alex ' |passwd --stdin alex # 设置密码,不需要交互 [root@localhost ~]# tail -l ...

  9. input属性为number时,如何去掉+、-号?

    直接上答案 <style> input[type='number']{-moz-appearance:textfield;} input[type=number]::-webkit-inn ...

  10. 获取邮箱的DNS和MX 工具类

    1.导入Maven  DNS  包: <dependency> <groupId>dnsjava</groupId> <artifactId>dnsja ...