0
我是新來的jQuery,並想從週一僅打印所有時間(或天==今日稍後)jQuery的打印對象的內容
我管理打印對象的所有時間,而不是1天我挑,也許我的迭代是錯誤的,想要任何提示。
var arr = [{
"dateString": "2016-12-05",
"weekday": "mon",
"opening_hours": [{
"from": "09:00",
"to": "15:00",
"fromNumber": 9,
"toNumber": 15
}, {
"from": "17:00",
"to": "20:00",
"fromNumber": 17,
"toNumber": 20
}]
}, {
"dateString": "2016-12-06",
"weekday": "tue",
"opening_hours": [{
"from": "09:00",
"to": "17:00",
"fromNumber": 9,
"toNumber": 17
}]
}, {
"dateString": "2016-12-07",
"weekday": "wed",
"opening_hours": [{
"from": "09:00",
"to": "20:00",
"fromNumber": 9,
"toNumber": 20
}]
}, {
"dateString": "2016-12-08",
"weekday": "thu",
"opening_hours": [{
"from": "1:00",
"to": "11:00",
"fromNumber": 1,
"toNumber": 11
}]
}];
$("button").click(function() {
var today = new Date();
var str = today.toString('dddd, MMMM ,yyyy')
var sta = str.substring(0, 4);
console.log(sta);
$.each(arr, function(i, currProgram) {
$.each(currProgram.opening_hours, function(key, val) {
// $.each(num, function (axa, dasa) {
if (currProgram.weekday == "mon") {
console.log("monday");
timefrom = (val.from);
timeto = (val.to);
} else {
console.log("no monday");
}
// console.log(num[axa]);
$(".result").append("\ntime: " + timefrom + " to " + timeto + "\n");
console.log("time: " + timefrom + " to " + timeto + "\n");
// });
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="calnote">
<day></day>
<br>
<month></month>
<blackcorner>
<em>
<time></time>
</em>
</blackcorner>
</p>
<div id="div1">
<h2>click button for ajax</h2></div>
<div class="result">
<br>
</div>result</div>
<br>
<div class="result1">
</div>result1</div>
<p class="calnote">
<day></day>
<br>
<month></month>
<blackcorner>
<em>
<time></time>
</em>
</blackcorner>
</p>
click event
<button class="abc">Click me</button> here
結果應該只打印:
時間:09:00至15:00
時間:17:00〜20 :00