我正在尝试使用 jQuery 更改 css,但是使用 jQuery 无法保存 mso-hide
属性。
还有什么其他解决方案可以使用 jQuery 执行此操作?
styleCSS = {
'display': 'none',
'height' : '0px',
'line-height' : '0px',
'max-height' : '0px',
'overflow' : 'hidden',
'font-size': '0px',
'mso-hide' : 'all',
'width' : '0px',
'max-width' : '0px'
}
$('.container').find('.hide-me').css(styleCSS);
最佳答案
您可以手动设置整个样式属性
var style_text = '';
$.each(styleCSS, function(k,v) {style_text += k+':'+v+';';});
$('.container').find('.hide-me').attr('style', style_text);
styleCSS = {
'display': 'none',
'height' : '0px',
'line-height' : '0px',
'max-height' : '0px',
'overflow' : 'hidden',
'font-size': '0px',
'mso-hide' : 'all',
'width' : '0px',
'max-width' : '0px'
};
var style_text = '';
$.each(styleCSS, function(k,v) {style_text += k+':'+v+';';});
$('.container').find('.hide-me').attr('style', style_text);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="hide-me">foo</div>
<div>bar</div>
</div>
关于jquery - 如何使用 Jquery 设置非标准的 css 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238714/