美文网首页
JS基础整理 -1

JS基础整理 -1

作者: 我就是个伪程序媛 | 来源:发表于2016-08-15 13:59 被阅读9次

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](https://img.haomeiwen.com/i1122152/1ed2cc8d09b594b3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

相关文章

  • JS基础整理 -1

    1 所有JavaScript数字均为64位,整数(不使用小数点或指数计数法)最多为15位。 2 绝不要在数字前面写...

  • js基础整理

    1 概念类 数据类型 内置函数 this的使用场景 同步和异步的区别并举例 原型和原型链 闭包 同源策略(跨域) ...

  • js基础整理

    for of es6属性 遍历value 对象必须可迭代for in es5 遍历key 对象自定义的key也会被...

  • 前端JavaScript面试技巧

    1-1 课程概述 要做什么?——讲解前端 JS 基础面试题 哪些部分?——JS 基础,JS-WEB-API,JS ...

  • 2018-12-20

    1.01.尚硅谷_JS基础_JS简介(1) 10.10.尚硅谷_JS基础_Null和Undefined(10) 1...

  • JS正则基础整理

    Regular Expression 正则表达式是指: 使用单个字符串来描述或者匹配一系列符合某个句法规则的字符串...

  • JS基础整理 - 4

    1函数就是包裹在花括号中的代码块,前面使用了关键词 function,例如: function functionn...

  • JS基础整理 - 2

    1 JavaScript Array(数组)对象 ![Array(数组)对象.png](http://upload...

  • JS语法基础整理

    块作用域 : { }JS中作用域有:全局作用域、函数作用域。没有块作用域的概念。ECMAScript 6(简称E...

  • JS整理(1)

    浏览器内核 常用的浏览器内核: -谷歌浏览器(chrome): Webkit内核 (V8引擎) safari、...

网友评论

      本文标题:JS基础整理 -1

      本文链接:https://www.haomeiwen.com/subject/dwdusttx.html