您的位置:首页 > Web前端 > JQuery

在页面加载完成后通过jquery给多个span赋html值(当前系统时间本地格式化new Date().toLocaleDateString(); )

2015-01-24 18:01 781 查看
文章来源: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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐