javascript jQuery中的while循环
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27164780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
while loop in jQuery
提问by Talha Habib
i need to use while loop, i wonder if there are any syntax changes in jQuery
我需要使用while循环,我想知道jQuery中是否有任何语法变化
in javascript
在 JavaScript 中
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;
how can i perform loop in jquery just like this?
我怎样才能像这样在 jquery 中执行循环?
回答by Anik Islam Abhi
There is no difference between javascript and jquery in case of while loop
在以下情况下,javascript 和 jquery 之间没有区别 while loop
$(function () {
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
$("#demo").html(text);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="demo"></div>
回答by shri
<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>
回答by Legendary Jaguarz
There is no difference in javascript and jquery while loops.
javascript 和 jquery while 循环没有区别。
$(document).ready(function () {
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}});
This will work.
这将起作用。
回答by Nelu
It would be the same in jQuery. Here is the documentation.
在 jQuery 中也是如此。这是文档。
There is a popular loop methodin jQuery, but it doesn't apply to your example. $.each()
allows you to loop through arrays and array-like objects.
jQuery 中有一个流行的循环方法,但它不适用于您的示例。$.each()
允许您遍历数组和类似数组的对象。