jQuery中的while循环

anhgbhbe  于 2024-01-07  发布在  jQuery
关注(0)|答案(4)|浏览(160)

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

在JavaScript中

  1. var text = "";
  2. var i = 0;
  3. while (i < 10) {
  4. text += "<br>The number is " + i;
  5. i++;
  6. }
  7. document.getElementById("demo").innerHTML = text;

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

mrzz3bfm

mrzz3bfm1#

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

  1. $(function () {
  2. var text = "";
  3. var i = 0;
  4. while (i < 10) {
  5. text += "<br>The number is " + i;
  6. i++;
  7. }
  8. $("#demo").html(text);
  9. });

个字符

af7jpaap

af7jpaap2#

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

字符串

edqdpe6u

edqdpe6u3#

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

m4pnthwp

m4pnthwp4#

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

  1. $(document).ready(function () {
  2. var text = "";
  3. var i = 0;
  4. while (i < 10) {
  5. text += "<br>The number is " + i;
  6. i++;
  7. }});

字符串
这会有用的

相关问题