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