Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为JQuery库创建无限循环?_Jquery - Fatal编程技术网

如何为JQuery库创建无限循环?

如何为JQuery库创建无限循环?,jquery,Jquery,我有一个Jquery代码 <script> document.addEventListener('DOMContentLoaded', function(){ Typed.new('.element', { strings: ["First sentence.", "Second sentence."], typeSpeed: 0 }); }); </script> document.addEventListener('DOMContent

我有一个Jquery代码

<script>
 document.addEventListener('DOMContentLoaded', function(){
  Typed.new('.element', {
    strings: ["First sentence.", "Second sentence."],
    typeSpeed: 0
  });
});
 </script>

document.addEventListener('DOMContentLoaded',function(){
Typed.new(“.element”{
字符串:[“第一句话”,“第二句话”。],
打字速度:0
});
});
我需要无限重复,我试着把代码放到while循环中

<script>
  document.addEventListener('DOMContentLoaded', function(){
  while(1){

  Typed.new('.element', {
    strings: ["First sentence.", "Second sentence."],
    typeSpeed: 0
  });
  }
});
 </script>

document.addEventListener('DOMContentLoaded',function(){
而(1){
Typed.new(“.element”{
字符串:[“第一句话”,“第二句话”。],
打字速度:0
});
}
});
但是它不起作用

有什么想法吗?

使用setInterval方法:

<script>
 document.addEventListener('DOMContentLoaded', function(){
 setInterval(function(){
     Typed.new('.element', {
      strings: ["First sentence.", "Second sentence."],
        typeSpeed: 0
       });          
   },100);
 });
</script>

document.addEventListener('DOMContentLoaded',function(){
setInterval(函数(){
Typed.new(“.element”{
字符串:[“第一句话”,“第二句话”。],
打字速度:0
});          
},100);
});
示例代码:

使用setInterval方法:

<script>
 document.addEventListener('DOMContentLoaded', function(){
 setInterval(function(){
     Typed.new('.element', {
      strings: ["First sentence.", "Second sentence."],
        typeSpeed: 0
       });          
   },100);
 });
</script>

document.addEventListener('DOMContentLoaded',function(){
setInterval(函数(){
Typed.new(“.element”{
字符串:[“第一句话”,“第二句话”。],
打字速度:0
});          
},100);
});

示例代码:

U可以在js中创建无限循环,如下所示:

function selfInvoke() {
alert(1);
selfInvoke();
}

selfInvoke();//but with time u can get an error
使用setInterval的更好解决方案:

function myFunction() {
    setInterval(function(){ alert("Hello"); }, 500);
}
myFunction();

你可以在js中创建无限循环,如下所示:

function selfInvoke() {
alert(1);
selfInvoke();
}

selfInvoke();//but with time u can get an error
使用setInterval的更好解决方案:

function myFunction() {
    setInterval(function(){ alert("Hello"); }, 500);
}
myFunction();

似乎有一个拼写错误,因为它不起作用。似乎有一个拼写错误,因为它不起作用