<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js赋值</title>
</head>
<body>
<script type="text/javascript">
//直接输出:
//document.write('不惧风雪,我中华儿女流血不流泪。');
//改为:
window.onload = function () {
document.getElementById("ctinfo").innerHTML = "不惧风雪,我中华儿女流血不流泪。";
}
</script>
<span id="ctinfo"></span>
<!--如果没有:<span id="ctinfo"></span> 或设计不合理,会报:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)-->
</body>
</html>
【js基础】替代document.write()
于 2022-04-08 22:35:12 首次发布