1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jsオフでも変にならないように年を自動更新

Last updated at Posted at 2019-02-27
hogehoge.html
<span id="copyright-year">2019</span>
hogehoge.js
var date = new Date();
var y = String(date.getFullYear());
var getCopy = $('#copyright-year');
var tx = getCopy.text();
var t = tx + ' - ' + y;

if (tx !== y) {
  getCopy.text(t);
}

htmlには公開年、もといjs無効の時に見せたい年を書いておく。
jsが動けば、公開から現在までを2018 - 20XXといったように表示。
※要jquery

兼投稿テストでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?