无法将孩子附加到父母

时间:2017-03-19 20:23:48

标签: javascript html

我有div我希望将渲染内容作为子项插入。这是<div class="top-news-bar"></div>。我有那个模块

    var fullNewsService = (function () {
    var TEMPLATE_FULL;
    var TOP_NEWS_CONTAINER;


    function init() {
        TEMPLATE_FULL = document.getElementById('template-full-news');
        TOP_NEWS_CONTAINER = document.querySelector('.top-news-bar');
        TOP_NEWS_CONTAINER.addEventListener('click', handleShowClick);
    }



    function handleShowClick(event) {
        var target = event.target;
        if (target.type != 'button')return;
        while (!target.hasAttribute('data-id')) {
            target = target.parentNode;
        }
        var id = target.getAttribute('data-id');
        var templ = renderFullNews(id);
        TOP_NEWS_CONTAINER.appendChild(templ);
    }
    function renderFullNews(id) {
        var article = articlesService.getArticle(id);
        var template = TEMPLATE_FULL;
        template.content.querySelector('.top-image-full').style.backgroundImage = "url(" + article.picture + ")";
        template.content.querySelector('.full-left').innerHTML = article.author;
        var description = template.getElementsByClassName('full-right');


        template.content.querySelector('.title-full').innerHTML = "<h5>" + article.title + "</h5>";
        template.content.querySelector('.content-full').textContent = article.summary;
        return template.content.querySelector('.full-news-wrapper').cloneNode(true);
    }

    return {
        init: init,

    }

}());

document.addEventListener('DOMContentLoaded', startApp);


function startApp() {
  fullNewsService.init();

}

当我点击按钮时,我得到了正确的ID并且模板已成功生成。但没有任何反应,没有错误,也没有附加。我的HTML http://pastebin.com/jHxH6zPa

0 个答案:

没有答案