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>在頁(yè)面加載完成后通過(guò)jquery給多個(gè)span賦值
由于我想在頁(yè)面加載完成后,有幾個(gè)地方顯示當(dāng)前時(shí)間,所以我需要給多個(gè)span賦值。
span代碼的寫法如下:
<span name="currentDate"></span> (多個(gè)span)
jQuery寫法:
<script> $(document).ready(function() { var currentDate = new Date().toLocaleDateString(); $("span[name='currentDate']").each(function() { $(this).text(currentDate); }); }); </script> 新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注