[英]Div's css style now showing up when javascript is inside of it
我有一个非常简单的页面(用于立即练习)。 我有一个带红色边框和蓝色背景的div。 div内是一个标签,用于调用外部js文件。 js在工作,但是div的边框消失了。
这是代码。
var myArray = [ "Item one", "Item two", "Item three" ]; var randomItemOne = myArray[Math.floor(Math.random() * myArray.length)]; document.body.innerHTML = randomItemOne;
.box1 { border: solid 2px red; width: 200px; height: 150px; background-color: skyblue; }
HTML <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Random Text Selector</title> <meta name="description" content="The HTML5 Herald"> <link rel="stylesheet" href="rt_style.css"> </head> <body> <div class="box1"> <script src="js/random.js"></script> </div> </body> </html>
var myArray = [ "Item one", "Item two", "Item three" ]; var randomItemOne = myArray[Math.floor(Math.random() * myArray.length)]; document.getElementsByClassName("box1")[0].innerText = randomItemOne;
.box1 { border: solid 2px red; width: 200px; height: 150px; background-color: skyblue; }
HTML <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Random Text Selector</title> <meta name="description" content="The HTML5 Herald"> <link rel="stylesheet" href="rt_style.css"> </head> <body> <div class="box1"> <script src="js/random.js"></script> </div> </body> </html>
我认为这是您要实现的目标。 如果我错了请指正我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.