简体   繁体   English

Javascript搜索和替换CSS内部

[英]Javascript search and replace inside of CSS

Is there a way to replace some values inside of a loaded css file? 有没有办法替换已加载的CSS文件中的某些值?

For example I have some css files loaded and I don't know its classes but I want to replace all the values that contain #FFFFFF with #000000 and also take effect immediately on the webpage. 例如,我加载了一些css文件,但我不知道其类,但是我想将所有包含#FFFFFF的值替换为#000000,并且也要立即在网页上生效。

Thanks! 谢谢!

Well this will do what you'd like. 好吧,这将满足您的要求。 Put it in a script tag at the top of your page. 将其放在页面顶部的脚本标签中。 I don't suggest this as a solution because it will go through all the elements on your page to figure out which ones to change, and change those that it found. 我不建议这样做,因为它会遍历页面上的所有元素以找出要更改的元素,并更改找到的元素。

Updated , missed the ); 已更新 ,错过了); at the end. 在末尾。

$(document).ready(function () {
    $('*').filter(function() { 
        return $(this).css('background-color') == "rgb(255, 255, 255)" 
    }).css('background-color', '#000')
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM