JavaScript的内置对象: math array data string
string (字符串):
1.字符串的定义:
(1)、 var str1 = "xxx"
(2)、var str2 = new String("xxx")
(3)、var str3 = String("xxx")
2.字符串的索引: (1)indexOf ("--") 返回字符串在该字符串中的索引的位置 ;如果不存在,则返回-1 (2)charAt (-)返回指定位置的字符 (3)charCodeAt (-) 返回指定位置的字符的ASCII值
3.字符串的截取:
(1)str.substr(-,-) substr 两个参数,表示从第一个参数的位置开始截取,截取第二个参数代表的长度 (2) str1.substring(2,5) substring 两个参数,表示从第一个参数的位置开始截取,截取第二个参数代表的位置
特别注意:substr和substring如果只有一个参数,都表示从当前位置开始截取,截取到末尾
4.字符串的其他方法:
(1)concat() 连接字符串
(2)replase () 替换
(3) slice()与substring() 功能相同
(4) split() 方法用于把一个字符串分割成字符串数组,返回数组
(5)toLowerCase() 方法用于把字符串转换为小写
(6)toUpperCase() 方法用于把字符串转换为大写
字符串的属性:length 表示是字符串的长度
math (数学)
1、Math.PI 圆周率
2、Math.E 自然数
3、Math.ceil 向上取整
4、Math.floor() 向下取整
5、Math.sqrt () 开平方
6、Math.pow () 幂次方
7、Math.abs() 绝对值
8、Math.round() 四舍五入
9、Math.random() 随机数
date(日期)
1、new Date() 返回当前的日期和时间
2、getFullYear() 从 Date 对象以四位数字返回年份
3、getMonth() 从 Date 对象返回月份 (0 ~ 11)
4、myDate.getDate 从 Date 对象返回一个月中的某一天 (1 ~ 31)
5、getDay 从 Date 对象返回一周中的某一天 (0 ~ 6)
6、getHours 返回 Date 对象的小时 (0 ~ 23)
7、getMinutes 返回 Date 对象的分钟 (0 ~ 59)
8、getSeconds 返回 Date 对象的秒数 (0 ~ 59)
9、getMilliseconds 返回 Date 对象的毫秒(0 ~ 999)
array(数组)
1、push() push表示为末尾位置增加一个元素
2、unshift() 表示在首位增加
3、shift() 在首部删除
4、pop () 在尾部删除
5、reverse() 取反
6、sort() sort方法排序使用的ASCII值排序,所以数字排序,需要注意 如果是两位以上数字sort(function (x,y) { return x - y;});
7、splice(-,-) 两个数值是表示从第一个数所对应的下标开始删除2个
BOM和DOM编程:
BOM(BOM(browser object model) 浏览器对象模型
DOM(document object model) 文档对象模型
window === 浏览器
history 历史记录
location 路径
screen 屏幕
navigator 浏览器内核信息
document 文档DOM
1、window.open() 打开新窗口
2、window.close() 关闭当前窗口
3、window.moveTo() 移动当前窗口 (相对于左上角)
4、window.resizeTo() 调整当前窗口的尺寸
5、window.moveBy() 移动当前窗口 (相对于鼠标)
6、window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面
history 历史记录
1、history.length 当前站点的浏览次数
2、history.back() 返回上一页
3、history.forward() 返回下一页
4、history.go() -1 表示向后,1表示向前
screen 屏幕
1、screen.width 屏幕宽度
2、screen.height 屏幕高度
3、screen.availWidth 获取除任务栏外系统屏幕的宽
4、screen.availHeight 获取除任务栏外系统屏幕的高
navigator 浏览器内核信息
1、navigator.userAgent 对象包含有关访问者浏览器的信息
location 位置
1、window.location.href 当前url
2、window.location.hostname 主机名称
3、window.location.host 主机名称 + 端口
4、window.location.port 端口
5、window.location.protocol 协议
6、window.location.search ?后面的值
7、window.location.hash 锚点后面的值










网友评论