[英]Div not showing up in javascript?
I'm doing the odin project and for the front-end webdev project, I have to create a grid using javascript/jQuery. 我正在做odin项目,对于前端webdev项目,我必须使用javascript / jQuery创建一个网格。 I tried using the createElement method but I was wondering how I would be able to make the div visible in html?
我尝试使用createElement方法,但我想知道如何在html中显示div? Am I going about this all wrong?
我要解决所有这些错误吗?
HTML: 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: JS:
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
document.body.appendChild(div);
Add background-color
添加
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);
Add more styling to make it visible, such as a border or background color. 添加更多样式以使其可见,例如边框或背景色。
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.