【问题标题】:Font color not changing in current date js code当前日期js代码中的字体颜色不变
【发布时间】:2013-11-30 15:55:14
【问题描述】:

所以我得到了一个计算当前日期的js代码,但是我不能改变字体的颜色。我尝试在 CSS 和 html 页面中进行更改。你能帮帮我吗?

<div id="day" style="width:248px; font-color: #fff; border-top: none; border-right: none; border-left: none; padding-bottom:2px; background-color:#acd373; font-size:12px;" > 

            <a style="float: left;" href="yesterday.html" > < </a>

            <script language="JavaScript" type="text/javascript">
            <!--

            var months = new Array(12);
            months[0] = "January";
            months[1] = "February";
            months[2] = "March";
            months[3] = "April";
            months[4] = "May";
            months[5] = "June";
            months[6] = "July";
            months[7] = "August";
            months[8] = "September";
            months[9] = "October";
            months[10] = "November";
            months[11] = "December";

            var current_date = new Date();
            month_value = current_date.getMonth();
            day_value = current_date.getDate();
            year_value = current_date.getFullYear();

            document.write( months[month_value] + " " +
            day_value + ", " + year_value);

            //-->
            </script>

            <a style="float: right;" href="tomorrow.html" > > </a>

        </div> 

这就是现在的样子,日期是黑色的,我想要白色的。试图在“样式”中更改 div,一切正常,包括字体大小,除了颜色。 http://s30.postimg.org/azxdl1co1/Captura_de_ecr_2013_11_30_s_15_47_40.png

【问题讨论】:

  • 一种更简洁(更不容易出错)的方式来编写该数组:var months = [ "January", "February", "March", ... "November", "December" ];
  • 我会听取你的建议,谢谢!

标签: javascript html css colors


【解决方案1】:

添加一个元素来设置颜色属性。

document.write("<span style='color:#fff;'>" + months[month_value] + " " + day_value + ", " + year_value+"</span>");

【讨论】:

    猜你喜欢
    • 2010-11-22
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多