将项目附加到div

时间:2015-10-17 05:53:26

标签: javascript jquery

我试图将这些项目附加到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>");
  }
});         

1 个答案:

答案 0 :(得分:0)

试试这个..

<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