[英]while loop in jQuery
我需要使用while循環,我想知道jQuery中是否有任何語法更改
在JavaScript中
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;
我怎樣才能像這樣在jquery中執行循環?
在while loop
,javascript和jquery之間沒有區別
$(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>
<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>
javascript和jquery while循環沒有區別。
$(document).ready(function () {
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}});
這將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.