如果放在iframe之后,字符串不会显示使用引导程序列表

时间:2016-03-29 11:38:56

标签: javascript html iframe

为什么parsedList.title未显示在嵌入式iframe旁边?

https://jsfiddle.net/bobbyrne01/9ztgxhd7/

HTML

<div id="content">

</div>

的javascript

var parsedList = [];
parsedList.push({'title': 'test', 'embed': '<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&amp;type=video%2Fmp4&amp;schema=imgur" width="200" height="160" scrolling="no" frameborder="0" allowfullscreen&gt;&lt;/iframe>'});
parsedList.push({'title': 'test2', 'embed': '<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&amp;type=video%2Fmp4&amp;schema=imgur" width="600" height="400" scrolling="no" frameborder="0" allowfullscreen&gt;&lt;/iframe>'});
parsedList.push({'title': 'test3', 'embed': '<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&amp;type=video%2Fmp4&amp;schema=imgur" width="300" height="160" scrolling="no" frameborder="0" allowfullscreen&gt;&lt;/iframe>'});
parsedList.push({'title': 'test4', 'embed': '<iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2F…key=2aa3c4d5f3de4f5b9120b660ad850dc9&amp;type=video%2Fmp4&amp;schema=imgur" width="600" height="200" scrolling="no" frameborder="0" allowfullscreen&gt;&lt;/iframe>'});

document.getElementById('content').innerHTML = '<div class="list-group">';
for (var i = 0 ; i < parsedList.length; i++){

  if (parsedList[i].embed != null){
    parsedList[i].embed = parsedList[i].embed.replace(/width=".*?"/, 'width="200"');
    parsedList[i].embed = parsedList[i].embed.replace(/height=".*?"/, 'height="160"');
    document.getElementById('content').innerHTML += '<a href="#" class="list-group-item">' + parsedList[i].embed + parsedList[i].title + '</a>';
  }
}
document.getElementById('content').innerHTML += '</div>';

2 个答案:

答案 0 :(得分:1)

embed属性没有iframe结束标记。这是你的工作代码。

Demo

allowfullscreen&gt;&lt;/iframe>

被这些

取代
allowfullscreen ></iframe>

parsedList

希望它有所帮助。

答案 1 :(得分:1)

请勿转义嵌入代码中的<>'embed': '<iframe class="embedly-embed" src="[...]" width="200" height="160" scrolling="no" frameborder="0" allowfullscreen> </iframe>'

https://jsfiddle.net/9ztgxhd7/3/