jQuery中的while循环

anhgbhbe  于 5个月前  发布在  jQuery
关注(0)|答案(4)|浏览(48)

我需要使用while循环,我想知道jQuery中是否有任何语法更改

在JavaScript中

var text = "";
    var i = 0;
    while (i < 10) {
        text += "<br>The number is " + i;
        i++;
    }
    document.getElementById("demo").innerHTML = text;

字符串
如何在jquery中执行循环?

mrzz3bfm

mrzz3bfm1#

while loop的情况下,JavaScript和jquery之间没有区别

$(function () {
    var text = "";
    var i = 0;
    while (i < 10) {
        text += "<br>The number is " + i;
        i++;
    }
    $("#demo").html(text);
});

个字符

af7jpaap

af7jpaap2#

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javescript">
    $(document).ready(function () {
    var text = "";
    var i = 0;
    while (i < 10) {
        text += "<br>The number is " + i;
        i++;
    }}); 
    </script>

字符串

edqdpe6u

edqdpe6u3#

在jQuery中也是一样。
jQuery中有一个流行的loop method,但它不适用于您的示例。$.each()允许您循环遍历数组和类似数组的对象。

m4pnthwp

m4pnthwp4#

JavaScript和jquery的while循环没有区别。

$(document).ready(function () {
var text = "";
var i = 0;
while (i < 10) {
    text += "<br>The number is " + i;
    i++;
}});

字符串
这会有用的

相关问题