[英]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.