将对象格式的style转换为字符串格式

时间:2023-03-09 15:08:27
将对象格式的style转换为字符串格式
var style = {
position:'absolute',
background:'red',
width:'2px',
height:'2px',
color:'#fff',
top:x,
left:y,
'z-index':1e5
};
var s = [];
$.each(style,function(i,n){
s.push(i+':'+n);
});
s = s.join(';')