您的位置:首页 > Web前端 > JQuery

如何利用 jQuery 修改 css 中带有 !important 的样式属性?

2017-05-05 11:18 716 查看

使用 jQuery 修改 css 中带有 !important 的样式属性

外部样式为:

div.test {
width:auto !important;
overflow:auto !important
}

通过 $("div.test").css("width","100px"); 和 $("div.test").css("width","100px !important"); 是无效的

要想修改 div 的 width,可以通过如下这种方式:

$("div.test").css("cssText", "width:650px !important;");

要想修改多个属性,可以这么做:

$("div.test").css("cssText", "width:650px !important;overflow:hidden !important");

特别注意:

cssText 属性,会把先前的 css 值全部给覆盖掉,为了保留先前其他的样式,可以这么做:

var cssText = $("div.test").attr("style") + ";width:650px !important;";
$("div.test").css("cssText": cssText);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: