JavaScript快速入门(二)
文件中引入JavaScript嵌入到HTML文件中
在body或者head中添加script标签
引入js文件
创建一个js文件
var age = 20;
console.log(age);在html文件中src引入改文件
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>引入网络来源文件,和引入本地的js文件一样,通过src
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 数据类型
原始数据类型:基本的数据类型(数值、字符串、布尔值)
复合数据类型:对象(一个对象可以看做是存放各种值得容器,由基础数据类型组成)
var user = {<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>"name":"ming",<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>age:20,<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>is_register:True} 特殊数据类型:null和undefined
typeof可以用来判断基础数据类型
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>算数运算符
加减乘除取余:+ 、-、*、/、%
自增或者自减相当于当前值+1或者-1
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>自增自减需要注意,有两种写法一种运算符号在前,一种运算符号在后,两种效果不一样
运算符号在前是先自增再运行,运算符号在后是先运行在自增
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 赋值运算符
赋值运算符表达式=赋值运算符+=x +=y 等同于 x= x+y-=x -=y 等同于 x = x-y*=x *= y 等同于 x = x*y/=x /= y 等同于 x = x/y%=x %= y 等同于 x = x % y比较运算符
比较运算符描述</tdtd小于/td/trtrtd>大于=大于或者等于==相等===严格相等!=不相等!==严格不相等== 和 ===区别
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>布尔运算符
取反运算符(!)
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>提示 undefind 、null、false、0、NaN、空字符串 取反都为true
且运算符(&&)
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>活运算符(||)
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 用Switch简化多个if...else....
swith后面跟表达式,case后面记得一定要加上break,不加上break会把后续的都执行,最后default就是以上case都不是执行
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 用三目运算符来代替if...else...
?y :x
表达式正确返回y,错误则返回x
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 字符串
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>用属性length来查看字符串长度
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>charAT查看索引位置的字符串
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>concat连接两个字符串,创建新的字符串,不影响老的字符串(拼接的如果不是字符串,也会先转为str再拼接)
同样也可以用“+”拼接
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>concat和+号的区别
+号会先运算数字类型在转,所以下方会先做1+2后再转字符串
concat不管什么,都会转字符串拼接
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>substring截取字符串,两个参数,参数1开始的位置的索引,第二个参数结束位置的索引(结束索引位置不取,左闭右开)
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>substr用法基本和substring一样,区别是第二个参数不在是结束位置的索引,而是字符串的长度
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>indexof查询字符串第一次出现的位置,不存在则返回-1
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>trim方法去除首尾两端的空格,包括\r \n \t都能去掉
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>split方法是按分隔符,返回一个分割出来的字符串数组
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body> 数组
查询、追加
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>遍历
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>数组静态方法Array.isArray():判断是否为数组
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>push()/pop()方法:改变原数组末尾增加或删除
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>shift()/unshift:改变原数组在数组起始位置添加或删除
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>join按指定分隔符拼接数组成员,默认都是逗号
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>concat数组合并
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>reverse翻转
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>indexof返回元素在数组中第一次出现的位置,没有则返回-1
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
<body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
来源:https://www.cnblogs.com/yetangjian/p/17253215.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页:
[1]