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>