当前位置:首页 > JavaScript知识点个人总结
Js Math对象常用方法 1.丢弃小数部分,保留整数部分
parseInt(5/2) parseFloat() 转化为浮点型数字
2.向上取整,有小数就整数部分加1
Math.ceil(5/2)
3,四舍五入.
Math.round(5/2)
4,向下取整
Math.floor(5/2)
Js正则表达式常用方法
replace
用来查找匹配一个正则表达式的字符串,然后使用新字符串代替匹配的字符串。 var result1 = a.replace(re,”Hello”);
//result1 = “Hello”
var result2 = b.replace(re,”Hello”); //result2 = “,world”
search
执行一个正则表达式匹配查找。如果查找成功,返回字符串中匹配的索引值。否则返回 -1 。 var index1 = a.search(re); //index1 = 0
var index2 = b.search(re); //index2 = -1 test()
test()方法搜索字符串指定的值,根据结果并返回真或假。 下面的示例是从字符串中搜索字符 “e” :
var patt1=new RegExp(“e”); document.write(patt1.test(“The best things in life are free”)); exec()
exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配,则返回 null。下面的示例是从字符串中搜索字符 “e” : 实例 1
var patt1=new RegExp(“e”); document.write(patt1.exec(“The best things in life are free”));
Js 常用Bom方法 Window 尺寸
有三种方法能够确定浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条)。
对于Internet Explorer、Chrome、Firefox、Opera 以及 Safari: ? window.innerHeight - 浏览器窗口的内部高度 ? window.innerWidth - 浏览器窗口的内部宽度 对于 Internet Explorer 8、7、6、5: ? document.documentElement.clientHeight ? document.documentElement.clientWidth 或者
? document.body.clientHeight ? document.body.clientWidth
实用的 JavaScript 方案(涵盖所有浏览器): 实例
var w=window.innerWidth
|| document.documentElement.clientWidth || document.body.clientWidth;
var h=window.innerHeight
|| document.documentElement.clientHeight || document.body.clientHeight;
其他 Window 方法 一些其他方法:
? window.open() - 打开新窗口 ? window.close() - 关闭当前窗口
共分享92篇相关文档