码迷,mamicode.com
首页 > 其他好文 > 详细

获得元素上的所有属性

时间:2015-11-11 14:35:34      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

function printStyles(elem) {

 

    var isIe  = navigator.userAgent.indexOf(‘MSIE‘) >= 0 ? true : false;

    var allStyle;

    if(isIe) {

        allStyle = elem.currentStyle;

    }else {

       allStyle = document.defaultView.getComputedStyle(elem,null);

    }

    var tmp = ‘‘;

    for(var i in allStyle) {

        if(typeof allStyle[i] != ‘string‘) continue;

        tmp += i+":"+allStyle[i] + "\n" ;

    }

    alert(tmp);

}

 

printStyles(document.getElementById(‘test‘));

 

获得元素上的所有属性

标签:

原文地址:http://www.cnblogs.com/ckaifeng/p/4955749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!