为什么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&type=video%2Fmp4&schema=imgur" width="200" height="160" scrolling="no" frameborder="0" allowfullscreen></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&type=video%2Fmp4&schema=imgur" width="600" height="400" scrolling="no" frameborder="0" allowfullscreen></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&type=video%2Fmp4&schema=imgur" width="300" height="160" scrolling="no" frameborder="0" allowfullscreen></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&type=video%2Fmp4&schema=imgur" width="600" height="200" scrolling="no" frameborder="0" allowfullscreen></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>';
答案 0 :(得分:1)
embed属性没有iframe
结束标记。这是你的工作代码。
allowfullscreen></iframe>
被这些
取代allowfullscreen ></iframe>
在parsedList
希望它有所帮助。
答案 1 :(得分:1)
请勿转义嵌入代码中的<
和>
:
'embed': '<iframe class="embedly-embed" src="[...]" width="200" height="160" scrolling="no" frameborder="0" allowfullscreen> </iframe>'