tumblr的随机背景颜色选择器 [英] Random background colour picker for tumblr

查看:96
本文介绍了tumblr的随机背景颜色选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中,这应该选择一个随机的背景颜色每次刷新,但我不能看到我的document.write

I've got this in my code, which should select a random background colour every refresh, but i can't see what's wrong with my document.write

var bgcolorlist=new Array("#ff871b", "#15efa1", "#51ddff", "#ff1b6c", "#000000")



document.write('<meta name="color:Background" content='+background=bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)] + '>')

干杯!

推荐答案

另一个解决方案是向您的正文添加ID,然后使用此代码:

Another solution is to add an ID to your body and then use this code:

<script>
    var bgcolorlist=new Array("background: #ff871b", "background: #15efa1", "background: #51ddff", "background: #ff1b6c", "background: #000000");
    var color = bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
    var d = document.getElementById("your-body"); 
    d.setAttribute("style", color);
</script>

据我所知,Tumblr允许你使用jQuery,这比纯JavaScript容易得多。如果您将jQuery添加到代码中,只需执行:

As far as I know, Tumblr allows you to use jQuery, which is way easier than pure Javascript. If you have jQuery added to your code, just do:

<script>
    var bgcolorlist=new Array("background: #ff871b", "background: #15efa1", "background: #51ddff", "background: #ff1b6c", "background: #000000");
    var color = bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
    $('body').css('backgroundColor', color);
</script>

这篇关于tumblr的随机背景颜色选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆