Shortest way to print current year in a website

前端 未结 12 531
鱼传尺愫
鱼传尺愫 2020-12-07 06:45

I need to update a few hundred static HTML pages that have the copyright date hard coded in the footer. I want to replace it with some JavaScript that will automatically upd

12条回答
  •  爱一瞬间的悲伤
    2020-12-07 07:35

    There are many solutions to this problem as provided by above experts. Below solution can be use which will not block the page rendering or not even re-trigger it.

    In Pure Javascript:

    window.addEventListener('load', (
        function () {
            document.getElementById('copyright-year').appendChild(
                document.createTextNode(
                    new Date().getFullYear()
                )
            );
        }
    ));
    ©

    In jQuery:

    $(document).ready(function() {
      document.getElementById('copyright-year').appendChild(
        document.createTextNode(
          new Date().getFullYear()
        )
      );
    });
    
    
    ©

提交回复
热议问题