嘿,我想提出一個網站,只是JavaScript,但我得到這個錯誤:JavaScript的網站錯誤:未捕獲的類型錯誤:無法執行「的appendChild」的「節點」
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'at html:12:9
這裏是我的html代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
var divEl = document.createElement("div");
document.body.appendChild(divEl);
var ptag = document.createElement("p").setAttribute("id", "lol");
divEl.appendChild(ptag);
</script>
</body>
</html>
'document.createElement(「p」)。setAttribute(「id」,「lol」);'不返回節點。 – vlaz