<div id="cp_opening_hours">
<h3 class="howtoreach openinghrs">Opening Hours</h3>
<span>Monday: 10.30 AM - 9.30 PM<br></span>
<span>Tuesday: 10.30 AM - 9.30 PM<br></span>
<span>Wednesday: 10.30 AM - 9.30 PM<br></span>
<span>Thursday: 10.30 AM - 9.30 PM<br></span>
<span>Friday: 10.30 AM - 9.30 PM<br></span>
<span>Saturday: 10.30 AM - 9.30 PM<br></span>
<span>Sunday: 10.30 AM - 9.30 PM<br></span></div>
...
var dayNames = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var nData = new Date();
jQuery( "#cp_opening_hours span" ).each(function(i) {
var to_day=jQuery(this).text();
to_day_new=to_day.split(" ");
to_day_new1=to_day_new[0].split(':');
span_pos=dayNames.lastIndexOf(dayNames[nData.getDay()]);
span_val=jQuery("#cp_opening_hours span:nth-of-type("+span_pos+")").text();
if(span_val!=undefined){jQuery("#thelanguage_new").append('<span>'+span_val+'</span>');}
jQuery("#cp_opening_hours span:nth-of-type("+span_pos+")").remove();
if(to_day_new1[0]=='Sunday')
{
jQuery(this).remove();
to_day_new_time=to_day.split(':');
main_today_time=to_day_new_time[1];
if(main_today_time=="Closed")
{
jQuery('#cp_opening_hours div').prepend('<span class="closed">Today: '+main_today_time+'<br/></span>');
}
else
{
jQuery('#cp_opening_hours div').prepend('<span class="open">Open Today: '+main_today_time+'<br/></span>');
}
}
});
jQuery("#thelanguage_new p:nth-of-type(1)").remove();
如果今天是星期三,我想显示今天基地的日期和时间。所以我想要这样
<div id="cp_opening_hours">
<h3 class="howtoreach openinghrs">Opening Hours</h3>
<span>Open Today: 10.30 AM - 9.30 PM<br></span>
<span>Thursday: 10.30 AM - 9.30 PM<br></span>
<span>Friday: 10.30 AM - 9.30 PM<br></span>
<span>Saturday: 10.30 AM - 9.30 PM<br></span>
<span>Sunday: 10.30 AM - 9.30 PM<br></span>
<span>Monday: 10.30 AM - 9.30 PM<br></span>
<span>Tuesday: 10.30 AM - 9.30 PM<br></span></div>
答案 0 :(得分:0)
也许你想要这种操作 - 我可以在以后给你一个更优雅的解决方案
var dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var today = new Date();
var fromToday = dayNames.slice(today.getDay());
var endDates = dayNames.slice(0,today.getDay());
var dayNamesSorted = fromToday.concat(endDates);
var $div = $("#cp_opening_hours");
$div.html('<h3 class="howtoreach openinghrs">Opening Hours</h3>');
$.each(dayNamesSorted,function(i,day) {
$div.append('<span>'+(i===0?"Today":day)+' '+': 10.30 AM - 9.30 PM</span><br/>');
});