[英]Div not showing up in javascript?
我正在做odin項目,對於前端webdev項目,我必須使用javascript / jQuery創建一個網格。 我嘗試使用createElement方法,但我想知道如何在html中顯示div? 我要解決所有這些錯誤嗎?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Etch-a-Sketch</title>
<link rel="stylesheet" type="text/css" href="etch-a-sketch.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type = "text/javascript" src="etch-a-sketch.js"></script>
</head>
<body>
</body>
</html>
JS:
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
document.body.appendChild(div);
添加background-color
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
div.style.backgroundColor = "yellow";//you forgot background color
document.body.appendChild(div);
添加更多樣式以使其可見,例如邊框或背景色。
var div = document.createElement("div"); div.style.width = "100px"; div.style.height = "100px"; div.style.color = "blue"; div.style.backgroundColor = "blue"; document.body.appendChild(div);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.