javascript - 你如何调整这个日期脚本的字体和字体系列

标签 javascript html css

<分区>

有没有办法为这个脚本添加字体:Arial 和颜色:白色?

<script>
            var date = new Date();
            days_change = -2;
            date.setDate(date.getDate() + days_change);
    
            const formattedDate = date.toLocaleString("en-GB", {
                day: "numeric",
                month: "long",
                year: "numeric",
            });
    
            document.write(formattedDate);
</script>

最佳答案

作为另一种解决方案。

您可以将 formattedDate 包装在 <span>...</span> 中用类标记。如这里:

document.write("<span class='date_arial'>" + formattedDate + "</span>");

并将所需的样式添加到 CSS。如这里:

.date_arial {
  font-family: Arial, sans-serif;
  color: #FFFFFF;
}

var date = new Date();
            days_change = -2;
            date.setDate(date.getDate() + days_change);
    
            const formattedDate = date.toLocaleString("en-GB", {
                day: "numeric",
                month: "long",
                year: "numeric",
            });
 
            document.write(formattedDate);
            
            document.write("<span class='date_arial'>" + formattedDate + "</span>");
body {
  background-color: green;
}

.date_arial {
  font-family: Arial, sans-serif;
  color: #FFFFFF;
}

关于javascript - 你如何调整这个日期脚本的字体和字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65713280/

相关文章:

javascript - 使用 JQuery 样式化嵌套滚动条

javascript - 类型错误 : Object doesn't support property or method 'finally'

Javascript 重定向循环仅在 IE8 上

javascript - 典型的 HTTP session ,但采用 Ajax 风格

javascript - browser.tabs.removeCSS 在 Chrome 扩展中不起作用?

html - 如何在侧边导航栏中为事件链接加下划线?在 Angular 应用程序中使用 Material 设计

fonts - CSS3 : Is there a way to alter Font Height?

html - 容器 div 未覆盖整个页面

html - 蓝图 : Push column partially in to another column

javascript - 根据一天中的时间(间隔 45 分钟)突出显示表行