【发布时间】:2019-02-25 11:15:02
【问题描述】:
我在悬停时收到一条关于已过期优惠的消息,显示为“优惠已过期”。现在我得到了消息。 由于我使用的 if 条件,我不希望在每个表格行中都显示消息。
我需要以红色显示消息。我该怎么做?
jquery
<script>
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var currentDate = d.getFullYear() + '-' + (month<10 ? '0' : '') + month + '-' + (day<10 ? '0' : '') + day;
$('tr:not(:first)').hover(
function() {
var enddate = $(this).find('.enddate').text();
if(currentDate > enddate) {
$(this).prop('title', "Offer Expired");
}
} );
</script>
查看
<table class="table">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Start Date</th>
<th scope="col">End Date</th>
<th scope="col">Description</th>
<th scope="col">Edit</th>
<!-- <th scope="col"></th> -->
</tr>
</thead>
<tbody>
<?php foreach($offerList as $info){ ?>
<tr>
<td><a href="<?php echo base_url()."offer/publicview/?id=".urlencode($this->encrypt->encode($info->offid)); ?> " ><?php echo $info->title; ?></a></td>
<td><?php echo $info->startdate; ?></td>
<td class="enddate"><?php echo $info->enddate; ?></td>
<!-- <td><?php echo $info->enddate; ?></td> -->
<td><?php echo $info->discrip; ?></td>
<td>
<a href="<?php echo base_url()."offer/edit/?id=".urlencode($this->encrypt->encode($info->offid)); ?>">Edit</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
更新
【问题讨论】:
-
您不能更改标题属性的颜色,这是由浏览器决定的。有一些插件,如 bootstraps popover 或类似的插件可以完成这项工作,甚至是 css 驱动的方法,它们会产生与标题 attr 相似的结果。
-
jsfiddle.net/vntj13ws/1 这会有帮助吗?
-
@samuellawrentz 是否可以在 if 条件下使用它?
标签: jquery codeigniter colors hover