<tfoot id='aapvD'></tfoot>

      • <bdo id='aapvD'></bdo><ul id='aapvD'></ul>
      <legend id='aapvD'><style id='aapvD'><dir id='aapvD'><q id='aapvD'></q></dir></style></legend>

    1. <small id='aapvD'></small><noframes id='aapvD'>

    2. <i id='aapvD'><tr id='aapvD'><dt id='aapvD'><q id='aapvD'><span id='aapvD'><b id='aapvD'><form id='aapvD'><ins id='aapvD'></ins><ul id='aapvD'></ul><sub id='aapvD'></sub></form><legend id='aapvD'></legend><bdo id='aapvD'><pre id='aapvD'><center id='aapvD'></center></pre></bdo></b><th id='aapvD'></th></span></q></dt></tr></i><div id='aapvD'><tfoot id='aapvD'></tfoot><dl id='aapvD'><fieldset id='aapvD'></fieldset></dl></div>

      在函数中使用设置间隔和获取

      Using set interval and fetch in a function(在函数中使用设置间隔和获取)
    3. <tfoot id='a1inZ'></tfoot>
            <bdo id='a1inZ'></bdo><ul id='a1inZ'></ul>

              <small id='a1inZ'></small><noframes id='a1inZ'>

              <i id='a1inZ'><tr id='a1inZ'><dt id='a1inZ'><q id='a1inZ'><span id='a1inZ'><b id='a1inZ'><form id='a1inZ'><ins id='a1inZ'></ins><ul id='a1inZ'></ul><sub id='a1inZ'></sub></form><legend id='a1inZ'></legend><bdo id='a1inZ'><pre id='a1inZ'><center id='a1inZ'></center></pre></bdo></b><th id='a1inZ'></th></span></q></dt></tr></i><div id='a1inZ'><tfoot id='a1inZ'></tfoot><dl id='a1inZ'><fieldset id='a1inZ'></fieldset></dl></div>
                <legend id='a1inZ'><style id='a1inZ'><dir id='a1inZ'><q id='a1inZ'></q></dir></style></legend>

                  <tbody id='a1inZ'></tbody>
              • 本文介绍了在函数中使用设置间隔和获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                创建一个函数startShowingMessage,它接受两个参数:一个元素和一个作为URL 的字符串.该函数将使用 setInterval 每 1 秒执行一次任务:获取 URL 并将响应文本放入提供的元素的文本内容中.

                我创建了函数并且获取工作,但我不知道如何在同一个函数中设置间隔,而不必调用另一个函数.

                异步函数 startShowingMessage(elem, url){常量响应 = 等待 fetch(url);常量文本 = 等待响应.文本();elem.textContent = 文本;}

                函数部分起作用,因为没有间隔.

                解决方案

                您可以根据需要使用 setInterval

                函数 startShowingMessage(elem, url){setInterval(异步函数(){常量响应 = 等待 fetch(url);常量文本 = 等待响应.文本();elem.textContent = 文本;}, 1000);}

                如果您想了解更多信息这里是 W3Schoolsp>

                或者官方文档可以找到根据 3limin4t0r 的建议,这里是 MDN 文档

                Create a function startShowingMessage that takes two parameters: an element and a string that is a URL. The function will use setInterval to make the following task every 1s: fetch the URL and put the response text into the text content of the provided element.

                I made the function and the fetch works, but i don't know how to set interval in the same function, without having to call another function.

                async function startShowingMessage(elem, url){
                  const response = await fetch(url);
                  const text = await response.text();
                  elem.textContent = text;
                }
                

                The functions works partially because there is no interval.

                解决方案

                you can use setInterval for your need

                function startShowingMessage(elem, url){
                  setInterval(async function(){
                    const response = await fetch(url);
                    const text = await response.text();
                    elem.textContent = text;
                  }, 1000);     
                }
                

                if you want to learn more about it here it is on W3Schools

                Or the official documentation can be found here on MDN documentation as suggested by 3limin4t0r

                这篇关于在函数中使用设置间隔和获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass
                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)

                        <tbody id='OsDWA'></tbody>
                      <tfoot id='OsDWA'></tfoot>

                      <small id='OsDWA'></small><noframes id='OsDWA'>

                        <bdo id='OsDWA'></bdo><ul id='OsDWA'></ul>

                          <legend id='OsDWA'><style id='OsDWA'><dir id='OsDWA'><q id='OsDWA'></q></dir></style></legend>
                          <i id='OsDWA'><tr id='OsDWA'><dt id='OsDWA'><q id='OsDWA'><span id='OsDWA'><b id='OsDWA'><form id='OsDWA'><ins id='OsDWA'></ins><ul id='OsDWA'></ul><sub id='OsDWA'></sub></form><legend id='OsDWA'></legend><bdo id='OsDWA'><pre id='OsDWA'><center id='OsDWA'></center></pre></bdo></b><th id='OsDWA'></th></span></q></dt></tr></i><div id='OsDWA'><tfoot id='OsDWA'></tfoot><dl id='OsDWA'><fieldset id='OsDWA'></fieldset></dl></div>