您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

重要的风格

重要的风格

我相信这样做的唯一方法是将样式添加为带有’!important’后缀的新CSS声明。最简单的方法是将新的<style>元素附加到文档的开头:

function addNewStyle(newStyle) {
    var styleElement = document.getElementById('styles_js');
    if (!styleElement) {
        styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.id = 'styles_js';
        document.getElementsByTagName('head')[0].appendChild(styleElement);
    }
    styleElement.appendChild(document.createTextNode(newStyle));
}

addNewStyle('td.EvenRow a {display:inline !important;}')

使用上述方法添加的规则(如果使用!important后缀)将覆盖其他先前设置的样式。如果您不使用后缀,请确保考虑“特异”之类的概念。

你可以使用几个简单的单线执行此操作。

1)在元素上设置“样式” 属性

element.setAttribute('style', 'display:inline !important');

要么…

2)修改对象的cssText属性style

element.style.cssText = 'display:inline !important';

两者都会做。

===

顺便说一句-如果你想要一个有用的工具来操作!important元素中的规则,

其他 2022/1/1 18:17:00 有375人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶