如何将jquery生成的HTML直接写到网页的实际文本中

时间:2018-08-31 16:28:29

标签: javascript jquery html

我有一个jQuery脚本,可为Youtube视频生成HTML播放列表。问题是我无法将jQuery生成的HTML写到页面中,因此视频无法加载或播放。

我已经用jQuery生成的HTML创建了一个字符串变量,我想直接将其插入到网页的后端文本中,但无法弄清楚。谢谢!

网站:http://www.dreamsspace.io/Test/Bigroom/

<div id="video-list"><br>
  Trying to insert jquery generated html code here--<br>
</div>

javascript文件(youtubeBigroom.js):生成html的循环

function resultsLoop(data) {
  $.each(data.items, function(i, item) {
    var thumb = item.snippet.thumbnails.medium.url;
    var title = item.snippet.title;
    var desc = item.snippet.description.substring(0, 100);
    var vid = item.snippet.resourceId.videoId;

    var strStr = `<div class="video-item" data-vidid="${vid}" data-imgurl="${thumb}" data-views="" data-likes="" data-date="2018-03-30T14:56:03.000Z" data-permalink="videos/${vid}/index.html"><a class="vid-img-link lazy-load-bg" href="#"><span class="duration">3:35</span><span class="play-button"><i class="fa fa-play"></i></span></a><div class="vid-content"><a class="vid-title-link" href="#"><h3>${title}</h3></a><div class="vid-meta"><span class="view-count"></span><span class="time-ago">5 months Ago</span></div>
      <div class="vid-description">${desc}</div>
    </div>
  </div>`
    strStr2 = strStr2 + strStr;
    // Can't figure out which line of code will write strStr2 into the html file??
    $('#video-list').html(strStr2);

0 个答案:

没有答案