简体   繁体   English

根据星期几使页面上的文本变为粗体

[英]Making text on page bold depending on day of the week

I have opening times of attractions on my site and I want it so the text is in bold depending on which day it is. 我在网站上有景点的开放时间,所以我希望它开放,因此文本会以粗体显示,具体取决于当天。 So, if it's Tuesday, 'Tuesday 10am - 4pm' will be in bold. 因此,如果是星期二,则“星期二上午10点至下午4点”将以粗体显示。 I have managed to get this to work for one attraction div but it doesn't work on any other attraction divs and i'm not sure why. 我设法使它适用于一个景点div,但是它不适用于其他景点div,我不确定为什么。

Website: explorecanterbury.co.uk (to view divs search or click on canterbury cathedral and westgate, as you can see canterbury cathedral works, but westgate doesn't). 网站:explorcanterbury.co.uk(要查看divs搜索或单击canterbury大教堂和westgate,您会看到canterbury大教堂的作品,而westgate则没有)。

HTML HTML

<div class="info-div col-md-5 col-xs-6" id="CDiv" style="background-color:orange;">
    <div class="close" onclick="hide('CDiv')"><span class="close-btn"></spam></div>
        <div class="content col-md-10">
            <h2 class="subtitle">Canterbury Cathedral</h1>
            <img src="images/test.jpg" class="img-responsive">
            <p>St Augustine, the first Archbishop of Canterbury, arrived on the coast of Kent as a missionary to England in 597 AD. He came from Rome, sent by Pope Gregory the Great.</p>
            <h2 class="subtitle">Find out more...</h1>
            <ul id="shareMenu">
                <li class="shareLi"><span class="webIcon"></span></li>
                <li class="shareLi"><span class="fbIcon"></span></li>
                <li class="shareLi"><span class="twitterIcon"></span></li>
                <li class="shareLi"><span class="instaIcon"></span></li>
            </ul>
            <h2 class="subtitle">Opening Times</h2>
            <ul style="list-style: none; padding: 0px;">
                <li><span class="weekday" id="1">Monday: 9am - 5.30pm</span></li>  
                <li><span class="weekday" id="2">Tuesday: 9am - 5.30pm</span></li>
                <li><span class="weekday" id="3">Wednesday: 9am - 5.30pm</span></li>
                <li><span class="weekday" id="4">Thursday: 9am - 5.30pm</span></li>
                <li><span class="weekday" id="5">Friday: 9am - 5.30pm</span></li>
                <li><span class="weekday" id="6">Saturday: 9am - 5.30pm</span></li>
                <li><span class="weekday" id="0">Sunday: 12.30pm - 2.30pm</span></li>    
            </ul>  
            <h2 class="subtitle">Related Attractions</h1>
                <div class="col-sm-6 col-md-12">
                    <div class="clearfix">
                        <div id="thumbcarousel" class="carousel slide" data-interval="false">
                            <div class="carousel-inner">
                                <div class="item active">
                                    <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="http://placehold.it/100/e8117f/fff&amp;text=Product+Main"></div>
                                    <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="http://placehold.it/100/00ffff/000&amp;text=Product+Image+2"></div>
                                </div><!-- /item -->
                                <div class="item">
                                    <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="http://placehold.it/100/612b65/fff&amp;text=Product+Image+5"></div>
                                    <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="http://placehold.it/100/00ffcc/000&amp;text=Product+Image+6"></div>
                                </div>
                                <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                                <span class="glyphicon glyphicon-chevron-left"></span>
                                </a>
                                <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                                <i class="glyphicon glyphicon-chevron-right"></i>
                                </a>
                            </div> 
                        </div>  
                    </div>
                </div>
            </div>  
        </div>
    </div>
</div>

<div class="info-div col-md-5 col-xs-6" id="WDiv" style="background-color:orange;">
    <div class="close" onclick="hide('WDiv')"><span class="close-btn"></spam></div>
        <div class="content col-md-10">
            <h2 class="subtitle">Westgate Towers</h1>
            <img src="images/test.jpg" class="img-responsive">
            <p>The Westgateis a medieval gatehouse in Canterbury,Kent, England. This 60-foot high western gate of the city wall is the largest surviving city gate in England. Built of Kentish ragstone around 1379, it is the last survivor of Canterbury's seven medieval gates, still well-preserved and one of the city's most distinctive landmarks. The Tower is a scheduled ancient monument and Grade I listed. Visitors can explore its rich history and take in the spectacular views of the city from the battlements viewpoint.</p>
            <h2 class="subtitle">Find out more...</h1>
            <ul id="shareMenu">
                <li class="shareLi"><span class="webIcon"></span></li>
                <li class="shareLi"><span class="fbIcon"></span></li>
                <li class="shareLi"><span class="twitterIcon"></span></li>
                <li class="shareLi"><span class="instaIcon"></span></li>
            </ul>
            <h2 class="subtitle">Opening Times</h2>
            <ul style="list-style: none; padding: 0px;">
                <li><span class="weekday" id="1">Monday: 11am - 4pm</span></li>  
                <li><span class="weekday" id="2">Tuesday: 11am - 4pm</span></li>
                <li><span class="weekday" id="3">Wednesday: 11am - 4pm</span></li>
                <li><span class="weekday" id="4">Thursday: 11am - 4pm</span></li>
                <li><span class="weekday" id="5">Friday: 11am - 4pm</span></li>
                <li><span class="weekday" id="6">Saturday: 11am - 4pm</span></li>
                <li><span class="weekday" id="0">Sunday: 11am - 4pm</span></li>    
            </ul>  
            <h2 class="subtitle">Related Attractions</h1>
                <div class="col-sm-6 col-md-12">
                    <div class="clearfix">
                        <div id="thumbcarousel" class="carousel slide" data-interval="false">
                            <div class="carousel-inner">
                                <div class="item active">
                                    <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="http://placehold.it/100/e8117f/fff&amp;text=Product+Main"></div>
                                    <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="http://placehold.it/100/00ffff/000&amp;text=Product+Image+2"></div>
                                </div><!-- /item -->
                                <div class="item">
                                    <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="http://placehold.it/100/612b65/fff&amp;text=Product+Image+5"></div>
                                    <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="http://placehold.it/100/00ffcc/000&amp;text=Product+Image+6"></div>
                                </div>
                                <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                                <span class="glyphicon glyphicon-chevron-left"></span>
                                </a>
                                <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                                <i class="glyphicon glyphicon-chevron-right"></i>
                                </a>
                            </div> 
                        </div>  
                    </div>
                </div>
            </div>  
        </div>
    </div>
</div>

CSS CSS

.highlight {
font-weight:bold;
}

JS JS

var today = new Date().getDay();

$("#" + today).addClass("highlight");

Try setting the class instead of the id. 尝试设置类而不是ID。

<span class="weekday d1">
<span class="weekday d2">
<span class="weekday d3">

etc 等等

var today = new Date().getDay();

$(".d" + today).addClass("highlight");

id=1 is duplicated in your html, this could cause troubles id = 1在您的html中重复,这可能会引起麻烦

You can remove the id tags altogether and highlight the correct line using :nth-of-type 您可以完全删除id标签,并使用:nth-of-type突出显示正确的行
This method highlights the correct day for both sets of lists. 此方法突出显示两组列表的正确日期。

HTML HTML

<li><span class="weekday"></span></li>
<li><span class="weekday"></span></li>
<li><span class="weekday"></span></li>

JS JS

var date = new Date();
var dayOfWeek = date.getDay();

$('li:nth-of-type(' + dayOfWeek + ')').find('.weekday').addClass('highlight');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM