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>热门推荐
10 爸爸生日的祝福语简短
11 回归岗位文案祝福语简短
12 生日祝福语宿舍舍友 简短
13 奶茶便利贴祝福语简短
14 元旦祝福语 简短独特群发
15 生日奶茶红包祝福语简短
16 谢谢学校老师祝福语简短
17 康复儿童六一祝福语简短
18 新年祝福语简短俏皮文案