我正在处理如下所示的html代码:
<div class="schedule-wrapper" id="js-schedule-wrapper" data-timezone="et"> <!-- when timezone et is selected from the ui, then data-timezone="et" displays here -->
<div class="schedule-show">
<div class="schedule-show-time">
<time datetime="12:15 15-04-2019" data-timezone="pt">12:15</time> <!-- date is here 15-04-2019 -->
<time datetime="13:15 15-04-2019" data-timezone="mt">13:15</time> <!-- date is here 15-04-2019 -->
<time datetime="15:15 15-04-2019" data-timezone="et">15:15</time> <!-- date is here 15-04-2019 -->
</div>
<div class="schedule-show-details">
<h2 class="schedule-show-name" tabindex="0">
Public Record
<span class="cpac-icon cpac-icon-chevron-thin-right" aria-hidden="true" style="background-image: none;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<path d="M21.2 16L9.774 4.128a1.114 1.114 0 0 1 0-1.566 1.089 1.089 0 0 1 1.55 0l12.528 12.653a1.114 1.114 0 0 1 0 1.566L11.324 29.434a1.087 1.087 0 0 1-1.55 0 1.114 1.114 0 0 1 0-1.566L21.2 16.001z"></path>
</svg>
</span>
</h2>
</div>
</div>
</div>
上面的HTML代码属于以下屏幕截图:
问题陈述: 我想知道我需要添加什么脚本,以便日期也可以按时间显示。
这是我尝试过的:
<script>
jQuery(function ($) {
$( "#js-schedule-wrapper" ).click(function() {
if( $('#js-schedule-wrapper').attr('data-timezone') === 'et') {
console.log( $(".schedule-show .schedule-show-time time").attr('datetime') );
return false;
}
else if( $('#js-schedule-wrapper').attr('data-timezone') === 'pt') {
if ($('.schedule-show .schedule-show-time time').attr('data-timezone') === 'pt') {
console.log( $(".schedule-show .schedule-show-time time").attr('datetime') );
return false;
}
}
else if( $('#js-schedule-wrapper').attr('data-timezone') === 'mt') {
if ($('.schedule-show .schedule-show-time time').attr('data-timezone') === 'mt') {
console.log( $(".schedule-show .schedule-show-time time").attr('datetime') );
return false;
}
}
})
})
</script>