gpt4 book ai didi

javascript - 我如何检查日期是否是今天,然后使用 jquery 打印特定文本?

转载 作者:行者123 更新时间:2023-11-27 23:00:32 25 4
gpt4 key购买 nike

我有以下代码:

.today-tag {margin-left:10px;color:red};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="day">Sunday<span class="today-tag"></span></div>
<div class="day">Monday<span class="today-tag"></span></div>
<div class="day">Tuesday<span class="today-tag"></span></div>
<div class="day">Wedsday<span class="today-tag"></span></div>
<div class="day">Thursday<span class="today-tag"></span></div>
<div class="day">Friday<span class="today-tag"></span></div>
<div class="day">Saturday<span class="today-tag"></span></div>

我想在星期几旁边添加“今天”这个词。有没有办法使用 jquery 检查日期是否是今天?我已经尝试过类似的方法,但没有用。

var getdate = new Date();

if(getdate == new Date()) {
$('.today-tag').text("TODAY")
}

在我的 php 文件中,我使用此代码输出商店的开/关时间:

<?php if ( $res=FunctionsV3::getMerchantOpeningHours($merchant_id)):?>
<?php foreach ($res as $val):?>
<div class="row">
<div class="col-md-3 col-xs-4 "></i>
<?php echo t($val['day'])?>
<span class="today-tag"></span>
</div>
<div class="col-md-6 col-xs-6 "><?php echo $val['hours']?></div>
<div class="col-md-3 col-xs-3"><?php echo $val['open_text']?></div>
</div>
<?php endforeach;?>
<?php else :?>
<p class="text-danger"><?php echo t("Not available.")?></p>
<?php endif;?>

最佳答案

好吧,只是为了好玩。

var today = new Date().getDay();
var days = [
'Sunday', 'Monday', 'Tuesday', 'Wedsday', 'Thursday', 'Friday', 'Saturday'
];
var daysContainer = document.getElementById('days');
days.forEach((day, index) => {
day = today === index ? day + ' today': day;
daysContainer.innerHTML += `
<div class="day">${day}<span class="today-tag"></span></div>
`;
});
#today-tag {margin-left:10px;color:red};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<section id="days"></section>

关于javascript - 我如何检查日期是否是今天,然后使用 jquery 打印特定文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52684972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com