js获取样式的兼容写法】的更多相关文章

var currentStyle = function(element){ return element.currentStyle || document.defaultView.getComputedStyle(element, null); }…
js中的获取样式是在是让人头疼,为了方便兼容多个浏览器,把设置样式封装成一个函数. 函数如下: function getStyle(element, property) { var value = element.style[property]; if(!value){ if(window.getComputedStyle) { //非IE value = window.getComputedStyle(element,null)[property]; } else if(element.cur…
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box1{ width: 100px; height: 100px; background-color: red; } </style> <script type="te…
currentStyle获取计算后的样式,也叫当前样式.最终样式.优点:可以获取元素的最终样式,包括浏览器的默认值,而不像style只能获取行间样式,所以更常用到.注意:不能获取复合样式如background属性值,只能获取单一样式如background-color等. currentStyle 在ie.opera上是可行的,无法适用于所有浏览器的getComputedStyle( obj , false ) 是支持 w3c (FF12.chrome 14.safari):在FF新版本中只需要第…
function getStyle(obj, attr) { if(obj.currentStyle) { return obj.currentStyle[attr]; } else { return getComputedStyle(obj, false)[attr]; } }…
网上有大把现成的代码,不过有点小小的瑕疵 例如目前最流行的 正则法: function getArgument(_arg) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return ""…
事件兼容 事件对象的兼容 获取键码兼容 默认行为兼容 阻止事件冒泡兼容 事件监听兼容 ---- 封装 删除事件监听兼容 ---- 封装 事件委托->获取事件源兼容…
event = event || window.event; if (event.stopPropagation) { event.stopPropagation(); } else { event.cancelBubble = true; }…
var time = "2018-03-12 11:11:11".split(/[- : \/]/); date = new Date(time[0], time[1]-1, time[2], time[3], time[4], time[5]); console.log(date);…
第一种情况就是宽高都写在样式表里,就比如#div1{width:120px;}.这中情况通过#div1.style.width拿不到宽度,而通过#div1.offsetWidth才可以获取到宽度. 第二种情况就是宽和高是写在行内中,比如style="width:120px;",这中情况通过上述2个方法都能拿到宽度. 小结,因为id.offsetWidth和id.offsetHeight无视样式写在样式表还是行内,所以我们获取元素宽和高的时候最好用这2个属性.注意如果不是写在行内styl…