您好!欢迎来到聚码网

聚码网

热门搜索: 相亲小程序    搭子源码    直播系统自有商城   
  • 封装函数,实现游览器兼容。
  • 聚码交流
  • 0 0
  • yhuxAvNbtxUM
    0000-00-00 00:00:00
  • 回帖
<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"><title>封装获取css属性</title><style>h1{width:300px;height:100px;background-color:red;}</style></head><body><h1>我是高100px,宽300px的红色长方形</h1><scripttype="text/javascript">varh1=document.getElementsByTagName('h1')[0];//标准浏览器console.log(window.getComputedStyle(h1)['width']);console.log(window.getComputedStyle(h1).height);//IE浏览器console.log(h1.currentStyle.width);console.log(h1.currentStyle.height);//封装函数//ele表示元素,zxc表示属性functiongabc(ele,zxc){//第一种varqwe=window.getComputedStyle(ele).zxc||ele.current.zxcconsole.log(qwe);//第二种if(window.getComputedStyle(ele)){window.getComputedStyle(ele).zxc}else{ele.current.zxc}}</script></body></html>这样封装对不对?
最近热帖
近期热议
联系我们
Q Q:317563994
电话:400-000-000
邮箱:317563994@qq.com
时间:09:00 - 17:00