JS基础整理 -1

1 所有JavaScript数字均为64位,整数(不使用小数点或指数计数法)最多为15位。

2 绝不要在数字前面写零或x,除非需要进行进制转换(0表示八进制,x为十六进制)。

3 JavaScript String(字符串)对象 实例

(1) 计算字符串的长度    

var txt="Hello World!"  

document.write(txt.length)

(2)为字符串添加样式

<body>

<script type = "text/javascript">

var txt="Hello World!"

document.write("Big: " + txt.big() + "")

document.write("Small: " + txt.small() + "")

document.write("Bold: " + txt.bold() + "")

document.write("Italic: " + txt.italics() + "")//斜体

document.write("Blink: " + txt.blink() + " (does not work in IE)")

document.write("Fixed: " + txt.fixed() + "")

document.write("Strike: " + txt.strike() + "")//删除线

document.write("Fontcolor: " + txt.fontcolor("Red") + "")

document.write("Fontsize: " + txt.fontsize(16) + "")

document.write("Lowercase: " + txt.toLowerCase() + "")

document.write("Uppercase: " + txt.toUpperCase() + "")

document.write("Subscript: " + txt.sub() + "")//Subscript: Hello World!

document.write("Superscript: " + txt.sup() + "")//Superscript: Hello World!

document.write("Link: " + txt.link("http://www.w3school.com.cn") + "")//链接

</script>

</body>

4 indexOf()方法,用于定位字符串中某一个指定的字符首次出现的位置

<body>

<script type = "text/javascript">

var str="Hello world!"

document.write(str.indexOf("Hello") + "")

document.write(str.indexOf("World") + "")

document.write(str.indexOf("world"))

</script>

</body>

查看结果:

0

-1

6

5 match()方法,查找字符串中特定的字符,并且如果找到的话,则返回这个字符。

<body>

<script type = "text/javascript">

var str="Hello world!"

document.write(str.match("world") + "")

document.write(str.match("World") + "")

document.write(str.match("worlld") + "")

document.write(str.match("world!"))

</script>

</body>

查看结果

world

null

null

world!

6 替换字符串replace()方法,用于在字符串中用某些字符替换另一些字符

<body>

<script type = "text/javascript">

var str="Visit Microsoft!"

document.write(str.replace(/Microsoft/,"W3School"))

</script>

</body>

查看结果

Visit W3School!

7 日期对象用于处理日期和时间

![闹钟.png](http://upload-images.jianshu.io/upload_images/1122152-1ed2cc8d09b594b3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • js基础篇(一)——数组的各种操作js基础篇(三)——DOM的各种操作 1. 创建字符串 一个字符串用于存储一系列...
    hanyuntao阅读 1,021评论 0 5
  • 一、DOM 什么是DOM?Document Object Model(文档对象模型)。DOM是针对HTML和XML...
    空谷悠阅读 1,038评论 0 2
  • 一、JS前言 (1)认识JS 也许你已经了解HTML标记(也称为结构),知道了CSS样式(也称为表示),会使用HT...
    凛0_0阅读 2,945评论 0 8
  • JavaScript 参考手册这个链接要参考,多使用 JavaScript 中的所有事物都是对象:字符串、数值、数...
    松哥888阅读 508评论 0 1
  • 1.JavaScript 中的所有事物都是对象:字符串、数值、数组、函数... 此外,JavaScript 允许自...
    ancientear阅读 385评论 0 2

友情链接更多精彩内容