文章来源:http://www.poluoluo.com/jzxy/201405/275004.html
由于我想在页面加载完成后,有几个地方显示当前时间,所以我需要给多个span赋值。
span代码的写法如下:<span name="currentDate"></span> (多个span)
jQuery写法:
<script>
$(document).ready(function() {
var currentDate = new Date().toLocaleDateString();
$("span[name='currentDate']").each(function() {<span style="color:#009900;">//循环遍历name为currentDate的span元素</span>
$(this).text(currentDate);<span style="color:#009900;">//并为该span元素赋html值或者$(this).html(currentDate)</span>
});
});
</script>