weixin_33743880 2014-08-14 16:48 采纳率: 0%
浏览 15

将<a>附加到<li>麻烦中

I am simply trying to append an a-tag into a li, but for some reason I cannot see why this doesn't work.

navListItem = '<li class="p-list-item"></li>';                
mainLink = '<a class="main-a" href="' + item.link + '"><span>"' + item.title + '"</span></a>'; 
$(navListItem).append(mainLink);
  • 写回答

3条回答 默认 最新

  • weixin_33735676 2014-08-14 16:55
    关注

    Your navListItem does not exist yet.

    append it to another html element first and change the last line to:

    $(".p-list-item").append(mainLink);
    
    评论

报告相同问题?