使用jQuery中时间标签中的datetime字符串 [英] Use the datetime string from the time tag in jQuery

查看:209
本文介绍了使用jQuery中时间标签中的datetime字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将datetime属性解析为另一个div.我不希望来自时间标签的实际字符串被格式化,而是想要解析ISO日期

I need to parse the datetime attribute to a different div. I don't want the actual string from the time tag as this is formatted but instead want to parse the ISO date

当前下面的代码在2012年2月1日终止,但我需要将其设置为2012-02-01T00:00:00Z

Currently the below code spits out 01 Feb 12 but I need it to be 2012-02-01T00:00:00Z

有可能这样做吗?

var p = $(this);
p.attr("data-date", p.find("span.openDate time").text());

<span class="openDate"><time datetime="2012-02-01T00:00:00Z">01 Feb 12</time><span>

谢谢

推荐答案

用以下代码替换代码:

var p = $(this);
p.attr("data-date", p.find("span.openDate time").attr("datetime"));

现在它将从datetime属性中获取内容

It will now take the content from the datetime attribute

datetime="2012-02-01T00:00:00Z"

所以data-date应该是

2012-02-01T00:00:00Z

这篇关于使用jQuery中时间标签中的datetime字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆