你有没有发现,一些网站的底部写着“版权2018-2023”,但年份永远不更新?这其实是个小问题,但也能说明网站是否有人维护。咱们今天就来聊聊怎么让网站的版权年份自己动更新,让访客知道你的网站是活的,内容是新的。一段简单的JavaScript代码,就能搞定!

效果展示

本站页面底部即见。

代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网站版权年份自动更新</title>
</head>
<body>
    <script type="text/javascript">
   <!-- Begin

       copyright=new Date();                 //取得当前的日期

       update=copyright.getFullYear();       //取得当前的年份

       document.write("© Copyright {自己设置开始时间}-"+ update + " 刘郎阁");//update为自动更新的年份

    //  End -->
</script>
</body>
</html>

完!