好的,所以我有一堆 HTML div 类和一个包含所有类的 ID。我需要在 Javascript 中使用相同的概念来产生相同的结果。任何帮助将不胜感激 :)。我的主要问题是我无法获得我编写的 JavaScript 代码来以与我编写的 HTML 相同的方式显示 CSS。
HTML:
<body>
<div id = "barOne">
<div class = standard>
<p> Magazine </p>
</div>
<div class = standard>
<p> Newspaper </p>
</div>
<div class = standard>
<p> English </p>
</div>
<div class = standard>
<p> Friends </p>
</div>
<div class = standard>
<p> Photos </p>
</div>
<div class = standard>
<p> Videos </p>
</div>
<div class = standard>
<p> Admin </p>
</div>
</div> <!-- End barOne-->
</body>
这是我将代码转换为 JavaScript 的尝试,关于我所缺少的任何想法?
function mainMenuBar() {
console.log("Mainmenubar invoked...");
var menuBarWrapper = document.createElement("div");
var btns = [];
var btnTxt = [];
for (var i = 0; i < 6; i++) {
btns.push(document.createElement("div"));//Adds a button
btnTxt.push(document.createElement("p"));//Adds a p tag
btns[i].className = "standard";
btns[i].id = "btn" + i;
//btns[i].setActive("onclick","clickFunction()");
//btnTxt[i].className = "";
btns[i].appendChild(btnTxt);//Adds the lbl to button
menuBarWrapper.appendChild(btnTxt[i]);
}
document.getElementById("document.body").appendChild(menuBarWrapper);
}
function clickFunction() {
console.log("clickFunc invoked");
}
这是我想要与当前使用上面显示的 HTML 代码呈现的 JavaScript 代码相对应的 CSS...
body{
background-color: f5f5f5;
}
.canvasGeneral {
height: 768px;
width: 1024px;
position:fixed;
left:50%;
background-color: f5f5f5;
height:768px;
/*overflow:hidden;*/
}
#barOne {
border-top: 1px solid #939393;
left: 0px;
width: 1024px;
bottom: 1px;
height 39px;
position:absolute;
padding-left: 35px;
/*Quick nav bar at the bottom, primary nav*/
}
.standard {
margin: 9px;
background-color:f5f5f5;
-moz-border-radius:4px;
-webkit-border-radius:4px;
border-radius:4px;
display:inline-block;
color: #939393;
font-family:helvetica;
font-size:13px;
font-weight:light;
padding:0px 33px;
text-decoration:none;
-webkit-transition: 0 .2s;
-moz-transition: 0s .2s;
-ms-transition: 0 .2s;
-o-transition: 0 .2s;
transition: 0 .2s;
}
.standard:active {
position:relative;
color: #007bff;
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: none;
transition: none;
}