teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

試したコードとエラーを追記

2020/02/08 11:56

投稿

babirudebiruba
babirudebiruba

スコア16

title CHANGED
File without changes
body CHANGED
@@ -56,4 +56,41 @@
56
56
  **data-start-date="2020/2/1 0:00" data-end-date="2020/2/6 16:50"** を
57
57
  **data-start-date="0:00" data-end-date="16:50"** のように出来ませんか?
58
58
 
59
- よろしくお願いします。
59
+ よろしくお願いします。
60
+
61
+ #追記
62
+
63
+ ネットで調べると、時間の取り出し方は書いてあったのですが、それの使い方がいまいちわかりませんでした。
64
+ 適当に書いてみたのを載せておきます。
65
+
66
+ エラーはUncaught ReferenceError: nowDatetime is not definedですが、そもそも記述方法間違えていると思いますので...
67
+
68
+ ```jQuery
69
+ $(function(){
70
+ setInterval(function(){
71
+ $(document).ready(function() {
72
+ $(".view_timer").each(function(index, target) {
73
+ var hour = nowDatetime.getHours();
74
+ var minute = nowDatetime.getMinutes();
75
+ var second = nowDatetime.getSeconds();
76
+ var startDate = $(this).attr("data-start-date");
77
+ var endDate = $(this).attr("data-end-date");
78
+ var nowDate = ("minute+second");
79
+ if (startDate) {
80
+ startDate = new Date(startDate);
81
+ } else {
82
+ startDate = nowDate;
83
+ }
84
+ if (endDate) {
85
+ endDate = new Date(endDate);
86
+ }
87
+ if (startDate <= nowDate && (!endDate || nowDate <= endDate)) {
88
+ $(this).show();
89
+ } else {
90
+ $(this).hide();
91
+ }
92
+ });
93
+ },4000);
94
+ });
95
+ });
96
+ ```