取整函数和样式属性访问
2018-04-25 本文已影响0人
追逐_chase

取整函数
1.向上取整 函数
//1.取整函数 去大的 向上取整
var num = Math.ceil(1.02);
console.log(num);
// 2
2.向下取整 函数
//2.向下取整
var num1 = Math.floor(1.5);
console.log(num1);
// 1
3.四舍五入
//3.四舍五入
var num2 = Math.round(1.6);
console.log(num2);
// 2
访问 CSS样式
- 主要 外部(使用<link>)和内嵌(使用<style>)样式表中的样式
1. obj.currentStyle ie opera 常用
2. window.getComputedStyle("元素", "伪类") w3c
//兼容性
function getStyle(obj,att) {
if (obj.currentStyle) {
return obj.currentStyle[att];
} else {
return window.getComputedStyle(obj,null)[att];
}
}
console.log( getStyle(box,"width"));