【问题标题】:Show / hide image depends on date显示/隐藏图像取决于日期
【发布时间】:2020-08-25 09:26:46
【问题描述】:

我希望根据年份在我的网站上显示不同的图像(生肖图像)。例如:3 月 21 日至 4 月 21 日期间显示“白羊座”形象,4 月 22 日至 21 日期间将显示“金牛座”形象等。 我正在寻找一个简单的代码或脚本来用 PHP 或 JS 来完成它。在互联网上没有找到类似的东西。

感谢您的帮助!

【问题讨论】:

    标签: javascript php date


    【解决方案1】:

    如果你只是google zodiac dates js,你很容易得到你的解决方案

    你可以很容易地构建自己的。

    这是最简单的一种

    const signs = ['Aries: The Ram','Taurus: The Bull','Gemini: The Twins','Cancer: The Crab','Leo: The Lion','Virgo: The Virgin','Libra: The Scales','Scorpio: The Scorpion','Sagittarius: The Archer','Capricorn: The Goat','Aquarius: The Water Bearer','Pisces: The Fish'];
    
    var sign = Number(new Intl.DateTimeFormat('fr-TN-u-ca-persian', {month: 'numeric'}).format(Date.now())) - 1;
    document.getElementById('sign').innerHTML  = signs[sign]
    console.log(signs[sign]);
        <h1>
          the value for this month sign is: <span id="sign"></span>
        </h1>

    【讨论】:

    • 感谢您的回答 Ahmed,这个 sn-p 似乎很完美......但我不是开发人员,所以,我不明白如何在 html 中显示“console.log”。 document.write() 似乎不起作用。
    • 如果你分享你的html,你想在哪里显示它,那么我可以告诉你
    • 我已经用你的 codepen 代码更新了答案,现在检查
    • 现在完美运行,非常感谢 Ahmed。对我来说,最后一步也是用图像替换每个文本数组符号。再次感谢。
    猜你喜欢
    • 2010-10-30
    • 2020-01-01
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多