如何为JQuery库创建无限循环?
我有一个Jquery代码如何为JQuery库创建无限循环?,jquery,Jquery,我有一个Jquery代码 <script> document.addEventListener('DOMContentLoaded', function(){ Typed.new('.element', { strings: ["First sentence.", "Second sentence."], typeSpeed: 0 }); }); </script> document.addEventListener('DOMContent
<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();
似乎有一个拼写错误,因为它不起作用。似乎有一个拼写错误,因为它不起作用