jquery - 如何使用 Jquery 设置非标准的 css 属性?

标签 jquery css

我正在尝试使用 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/

相关文章:

css - 将 div 宽度设置为没有内联 block 的内容

html - 如何使用 bootstrap 等 css 制作响应式英雄图像

html - 多重背景

html - 在很多元素中使用 !important 可以吗?如果不是如何解决这个问题

javascript - 如何延迟 jquery validate 插件的 key up 事件验证?

javascript - 如何通过 document.getElementById ("BtnID").click() 调用 onclick/button 按下效果

JavaScript 函数被触发?

javascript - jQuery 事件处理程序无法正常工作

javascript - 如何在提交后保留选定的onchange下拉列表值

html - 将相关文本保留在 float 图像旁边