<h4>here is time<time datetime="2018-11-18">18.11.2018</time>!</h4>
也许,这很简单,但我如何从时间元素中的datetime获取日期?
Pure JS:
document.getElementsByTagName('time')[0].getAttribute('datetime');
在jQuery中:
console.log($('time:first').attr('datetime'));
console.log(document.getElementsByTagName('time')[0].getAttribute('datetime'));
console.log($('time:first').attr('datetime'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h4>here is time<time datetime="2018-11-18">18.11.2018</time>!</h4>