<script type="text/javascript"> alert(document.getElementById("test_div").style.border); </script>
safari和chrome上运行alert出来结果为空,IE、FF、Opera都有值。
演示: http://kindsoft.net/test/style_border_test.html
奇怪的是style.borderTop可以取得border,但style.borderLeft,style.borderBottom,style.borderRight都不行。
浏览器版本:
Windows XP, safari 3.2
Windows XP, chrome 1.0.154.36
问题补充:
应该是safari和chrome的BUG,style.border是W3C标准。
http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle
问题补充:
这个是Webkit的BUG,已经修复好了,只不过Safari和Chrome还没用最新版本Webkit,所以问题还在。
https://bugs.webkit.org/show_bug.cgi?id=15823
safari上BUG多了去了。。。
那个什么失去焦点事件也不支持。只支持 input text
所以在浏览器某些兼容点的时候就没考虑那浏览器了。只能等升级。
不过有另一个方式。
safari是能够通过document.getElementById(id).getAttribute("style");来取得style属性值的。
获得一个字符串。
然后通过正则查找出对应的属性即可。
因为属性定义通常都是
border:1px #CCC solid;这样的
具体查找代码我就不给出了。
新年快乐
截取一段代码给你参考
/*获取elem的某个style属性*/ function getStyle(elem, property){ if (property=='class') property='className'; else property=this.camelize(property); if (elem.currentStyle)// IE5+ return elem.currentStyle[property]; if(elem.style[property]) return elem.style[property]; if (document.defaultView.getComputedStyle)// FF/Mozilla var currentStyle = document.defaultView.getComputedStyle(elem, null); else if (window.getComputedStyle)// NS6+ var currentStyle = window.getComputedStyle(elem, null); return currentStyle[property] || currentStyle.getPropertyValue(this.uncamelize(property)); }