[英]Change width and height using Javascript
I am currently working on a simple task, changing the width and height of a div id using javascript.我目前正在处理一个简单的任务,使用 javascript 更改 div id 的宽度和高度。 This is my code and I just can't get it to work.这是我的代码,我无法让它工作。 Is there something I'm forgetting to add?有什么我忘记添加的吗?
HTML: HTML:
<!doctype html>
<html>
<head>
</head>
<body>
<div id="box">
Hello!
</div>
<script src="main.js"</script>
</body>
</html>
Javascript: Javascript:
function changeSize() {
document.getElementById('box').setAttribute("style","display:block;width:300px;background-color:blue;");
document.getElementById('box').style.width='300px';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.