0

我的博客是http://nefelisdreams.blogspot.com/

我发现这段代码随机改变所有十六进制值的帖子背景颜色

<script type='text/javascript'>
    //<![CDATA[
    function get_random_color() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
    color += letters[Math.round(Math.random() * 14)];
    }
    return color;
    }
    $(function() {
    $(".post").each(function() {
    $(this).css("background-color", get_random_color());
    });
    });
    //]]>
    </script>

also found this code which uses predefined hex values to randomly choose from

<script type="text/javascript">
    $(document).ready(function(){
        var colors = ["#556270","#00adf3","#0e94ec","#81d8d0","#fa023c","#a66c9d","#ffcc00","#cf3140"];
        var rand = Math.floor(Math.random()*colors.length);
    $('.title').css("color", colors[rand]);
    });
</script>

我想组合这些代码,以便我可以从预定的颜色列表中随机更改每个帖子背景颜色

提前致谢

4

0 回答 0