尝试编写一个do-while循环语句,打印出我的语句,但它当前没有打印它

时间:2015-09-15 19:09:23

标签: javascript html5 loops do-while

所以,我正在尝试编写一个do-while循环语句,打印出我的循环语句,但我的浏览器不打印我的文本。如何编辑我的代码呢?

<!DOCTYPE html>
<html>
<head>
    <title>9. Looping Statements in Javascript</title>
</head>
<body>
    <h1>9. Looping Statements in Javascript</h1>
    <div id="playlist"></div>
    <div id="someResult"></div>
    <script>
        var playlist = [];
        playlist[0] = "Willy Wesly";
        playlist[1] = "Childish Gambino";
        playlist[2] = "Chance The Rapper";
        playlist[3] = "Travi$ Scott";
        playlist[4] = "Yeezy";

// while
    /*
    var i = 0;
    while (i < playlist.length) {
        var element = document.createElement('div');
        element.innerHTML = "Now Playing:  " + playlist[i];
         i++;
        document.body.appendChild(element);
}
*/

// do - while
var someResult = false;
do {
    var element = document.createElement('div');
    element.innerHTML = 'Will print AT LEAST once!';
}
while(someResult);
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要将元素添加到文档正文中。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="video-container youtube">
    <iframe id="myvideo" width="964" height="544" src="http://www.youtube.com/embed/Eol8eo4WDKY?enablejsapi=1&amp;html5=1&amp;showinfo=0&amp;controls=0&amp;rel=0&amp;loop=1&amp;modestbranding=1&amp;autoplay=1" frameborder="0" allowfullscreen=""></iframe>
</div>
<div class="item_desc">
    <p>
        <iframe src="//www.youtube.com/embed/JfOD35Ebo5A" width="640" height="480" allowfullscreen="allowfullscreen" style="display: block; margin-left: auto; margin-right: auto; "></iframe>
    </p>
</div>

JSFiddle显示:http://jsfiddle.net/azgxh59q/