求大佬解答

Enchanted, 2019-06-10 07:10:45
在一个DIV内,根据当前日期动态计算并显示如下信息。
...全文
354 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
2019-06-14
  • 打赏
  • 举报
回复

<script src="https://cdn.bootcss.com/dayjs/1.8.14/dayjs.min.js"></script>
<script type="text/javascript">
var day = (new Date('2019-12-31') - new Date()) / (24 * 60 * 60 * 1000);
var str = dayjs().format('今天是YYYY年MM月DD日<br/>');
str += "距2019年12月31日还有还有" + Math.floor(day) + "天!";
document.write(str);
</script>
cn00439805 2019-06-14
  • 打赏
  • 举报
回复

<style>
#result{border:2px solid #1B2A0B;background:#92D14F;display:inline-block;padding:2px 60px 8px;text-align:center;}
#result p{margin:0;padding:2px 0;}
</style>
<div id="result"></div>
<script>
    let today = new Date(),
        todayMS = today.getTime(),
        targetMS = new Date("2019-12-31").getTime(),
        leftMS = targetMS - todayMS,
        leftDays = Math.max(0,Math.ceil(leftMS/1000/60/60/24)),
        todayYear = today.getFullYear(),
        todayMonth = today.getMonth() + 1,
        todayDay = today.getDate();
    document.getElementById('result').innerHTML = 
    `
        <p>今天是${todayYear}年${todayMonth}月${todayDay}日</p>
        <p>距2019年12月31日还有还有${leftDays} 天!</p>
    `;
</script>
Enchanted, 2019-06-14
  • 打赏
  • 举报
回复
引用 11 楼 cn00439805的回复:
不是已经放在哪个result的div里了吗
我的意思是放在一个那个绿色框里,就像上边图片那样
cn00439805 2019-06-14
  • 打赏
  • 举报
回复
不是已经放在哪个result的div里了吗
Enchanted, 2019-06-14
  • 打赏
  • 举报
回复
引用 9 楼 cn00439805的回复:
好使了,怎么把这个放一个div中啊?
cn00439805 2019-06-14
  • 打赏
  • 举报
回复
cn00439805 2019-06-14
  • 打赏
  • 举报
回复
3楼得不好使? 3楼就是原生js代码
Enchanted, 2019-06-14
  • 打赏
  • 举报
回复
引用 5 楼 囧的回复:

<script src="https://cdn.bootcss.com/dayjs/1.8.14/dayjs.min.js"></script>
<script type="text/javascript">
var day = (new Date('2019-12-31') - new Date()) / (24 * 60 * 60 * 1000);
var str = dayjs().format('今天是YYYY年MM月DD日<br/>');
str += "距2019年12月31日还有还有" + Math.floor(day) + "天!";
document.write(str);
</script>
好使了(✪▽✪) 怎么给它放一个Div里啊
Enchanted, 2019-06-14
  • 打赏
  • 举报
回复
引用 5 楼 囧的回复:

<script src="https://cdn.bootcss.com/dayjs/1.8.14/dayjs.min.js"></script>
<script type="text/javascript">
var day = (new Date('2019-12-31') - new Date()) / (24 * 60 * 60 * 1000);
var str = dayjs().format('今天是YYYY年MM月DD日<br/>');
str += "距2019年12月31日还有还有" + Math.floor(day) + "天!";
document.write(str);
</script>
程序运行不了啊???没有反应
Enchanted, 2019-06-12
  • 打赏
  • 举报
回复
大哥,得用JS代码啊
cn00439805 2019-06-10
  • 打赏
  • 举报
回复

<div id="result"></div>
<script>
    let today = new Date(),
        todayMS = today.getTime(),
        targetMS = new Date("2019-12-31").getTime(),
        leftMS = targetMS - todayMS,
        leftDays = Math.max(0,Math.ceil(leftMS/1000/60/60/24)),
        todayYear = today.getFullYear(),
        todayMonth = today.getMonth() + 1,
        todayDay = today.getDate();
    document.getElementById('result').innerHTML = 
    `
        <p>今天是${todayYear}年${todayMonth}月${todayDay}日</p>
        <p>距2019年12月31日还有还有${leftDays} 天!</p>
    `;
</script>
cn00439805 2019-06-10
  • 打赏
  • 举报
回复

<div id="result"></div>
<script>
    let today = new Date(),
        todayMS = today.getTime(),
        targetMS = new Date("2019-12-31").getTime(),
        leftMS = targetMS - todayMS,
        leftDays = Math.max(0,Math.ceil(leftMS/1000/60/60/24)),
        todayYear = today.getFullYear(),
        todayMonth = today.getMonth() + 1,
        todayDay = today.getDay();
    document.getElementById('result').innerHTML = 
    `
        <p>今天是${todayYear}年${todayMonth}月${todayDay}日</p>
        <p>距2019年12月31日还有还有${leftDays} 天!</p>
    `;
</script>
Enchanted, 2019-06-10
  • 打赏
  • 举报
回复
今天是XXXX年XX月XX日
距2019年12月31日还有还有XX 天!

87,903

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧