我有一個這樣的HTML代碼。jQuery目標類別單獨
<!-- Every time string is different -->
<span class="time_string">123456789</span>
<span class="time_string">981251100</span>
<span class="time_string">051036626</span>
<span class="time_string">016165656</span>
我想Jquery的更改時間的字符串到日期
<!-- Look every date is different -->
<span class="time_string">25 March 2017</span>
<span class="time_string">28 April 2017</span>
<span class="time_string">14 January 2017</span>
<span class="time_string">21 December 2015</span>
要做到這一點我已經使用這個jQuery代碼:
<script type="text/javascript">
function timestr_to_date(time_string){
// this function will convert the time string to date
}
$(document).ready(function(){
// getting the time string
var time_string = $('.time_string').html();
// converting the time string to date by using function
var date = timestr_to_date(time_string);
// replacing the time_string to date
$('.time_string').html(date);
});
</script>
但我有每個日期相同
<!-- PROBLEM: Every date are same -->
<span class="time_string">25 March 2017</span>
<span class="time_string">25 March 2017</span>
<span class="time_string">25 March 2017</span>
<span class="time_string">25 March 2017</span>
嗯..因爲沒有限制,我不知道我會有多少。我將使用PHP來生成這些。並沒有固定的號碼 – JaTurna
這裏根本就不需要id。因爲它不會限制元素的數量,或者需要任何未來的維護,所以類是完美的。 –
@JaTurna啊我覺得這很公平,那麼:)會刪除我的評論:D – ThisGuyHasTwoThumbs