js獲取css屬性

今天因需要用到js獲取css屬性,網上搜了半天都不合適的。有一下幾種方法:

var getstyle = function(elementID,attribute){
	obj = document.getElementById(elementID);
//	前面是IE後面是html的標準
	return obj.currentStyle ? obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj, false)[attribute];
}

還有一種可以獲取寫在html中的style屬性的 

document.getElementById("elementId").style.paddingLeft;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章