js給span標(biāo)簽賦值的方法?一般有兩種方法:
第一種方法:輸出html
<body onload="s()"><span id="hello"></span><script language="javascript"> function s(){document.getElementById("hello").innerHTML = "<iframe src= height=400 width=300></iframe>";} </script>
第二種方法:輸出文本
<body onload="s()"><span id="hello"></span><script language="javascript"> function s(){document.getElementById("hello").innerText = "hello world";}</script>
在頁面加載完成后通過jquery給多個span賦值
由于我想在頁面加載完成后,有幾個地方顯示當(dāng)前時間,所以我需要給多個span賦值。
span代碼的寫法如下:
<span name="currentDate"></span> (多個span)
jQuery寫法:
<script> $(document).ready(function() { var currentDate = new Date().toLocaleDateString(); $("span[name='currentDate']").each(function() { $(this).text(currentDate); }); }); </script>