javascript 當(dāng)頁(yè)面dom模型加載完成后才執(zhí)行javascript
不能使用<body>
加上 defer 等于在頁(yè)面完全在入后再執(zhí)行,相當(dāng)于 window.onload ,但應(yīng)用上比 window.onload 更靈活
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無(wú)標(biāo)題文檔</title>
</head>
<body>
<script defer="defer">
alert("頁(yè)面加載完我才執(zhí)行的")
</script>
先看到這段話 然后再執(zhí)行上面的 JS 如果去掉上面的 defer="defer" 那么會(huì)先執(zhí)行JS 在看到這段話
</body>
</html>
新聞熱點(diǎn)
疑難解答
圖片精選