javascript给span标签赋值的方法
js给span标签赋值的方法?一般有两种方法:
第一种方法:输出html
<bodyonload="s()">
<spanid="hello"></span>
<scriptlanguage="javascript">
functions(){
document.getElementById("hello").innerHTML="<iframesrc=height=400width=300></iframe>";
}
</script>
第二种方法:输出文本
<bodyonload="s()">
<spanid="hello"></span>
<scriptlanguage="javascript">
functions(){
document.getElementById("hello").innerText="helloworld";
}
</script>
在页面加载完成后通过jquery给多个span赋值
由于我想在页面加载完成后,有几个地方显示当前时间,所以我需要给多个span赋值。
span代码的写法如下:
<spanname="currentDate"></span>(多个span)
jQuery写法:
<script>
$(document).ready(function(){
varcurrentDate=newDate().toLocaleDateString();
$("span[name='currentDate']").each(function(){
$(this).text(currentDate);
});
});
</script>热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下