我试图将此项目附加到div,但它没有工作…下面是我的代码:
$("document").ready(function (){
var aMenu = [{
title: "Home",
image: "/Icons/1.png",
items: [
{ title: "about", w: "x", h: "y", image: "/Images/1-1.PNG" },
{ title: "feature", w: "x", h: "y", image: "/Images/1-2.PNG" },
{ title: "themes", w: "x", h: "y", image: "/Images/1-3.PNG" },
{ title: "typography", w: "x", h: "y", image: "/Images/1-4.PNG" },
{ title: "look", w: "2x", h: "y", image: "/Images/1-5.PNG" }
]
}];
var dv = ("#dvTitleMenu");
for (i = 0; i < aMenu.length; i++) {
$("#dvTitleMenu")
.append("<div class='col6'><a href='#'><h2>"+aMenu(i).title+"</h2></a></div>");
}
});
试试这个…
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<div id="dvTitleMenu"></div>
<script>
$("document").ready(function (){ var aMenu = [{
title: "Home", image: "/Icons/1.png",
items: [{ title: "about", w: "x", h: "y", image: "/Images/1-1.PNG" },
{ title: "feature", w: "x", h: "y", image: "/Images/1-2.PNG" },
{ title: "themes", w: "x", h: "y", image: "/Images/1-3.PNG" },
{ title: "typography", w: "x", h: "y", image: "/Images/1-4.PNG" },
{ title: "look", w: "2x", h: "y", image: "/Images/1-5.PNG" }]
}]
var dv = ("#dvTitleMenu");
for (i = 0; i < aMenu.length; i++) {
//console.log(aMenu.items.length);
console.log(aMenu[i].items);
$("#dvTitleMenu").append("<div class='col6'><a href='#'> <h2> " +aMenu[i].title + "</h2></a></div> ");
} });
</script>
http://js.do/code/70795