【发布时间】:2019-09-24 06:34:15
【问题描述】:
我正在尝试将 javascript 转换为 css 样式,我能够转换为 css 格式,但是,出现了问题。我无法删除双引号 " 或 ' 符号。
var out = console.log,
a = {
".time":{
"color":"red",
'background-color':'yellow',
height:'10%',
zindex:1
},
'#next':{
'colour':'#eee'
},
div:{
width:10,
'-webkit-hyphenate-character': 'auto'
},
"@keyframes example" : {
"0%" : {"background-color": 'red'},
"25%" : {"background-color": 'yellow'}
}
}
var toStyles = function(object){
var store = '';
Object.keys(object).forEach(name => {
var value = object[name];
if(typeof value == 'object'){
}
var style = name+':'+JSON.stringify(value)+';';
store = store + style;
});
console.log(store)
}
toStyles(a)
我的输出:-
.time{
"color":"red",
"background-color":"yellow",
"height":"10%",
"zindex":1
};
#next{
"colour":"#eee"
};
div{
"width":10,
"-webkit-hyphenate-character":"auto"
};
@keyframes example{
"0%":{"background-color":"red"},
"25%":{"background-color":"yellow"}
};
如何将这样的对象转换为正确的 css 样式。
请帮帮我
【问题讨论】:
标签: javascript css object