![用户在 用户在]()
本文介绍了我想在运行时由用户在javascript的setinterval中更改超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hello亲爱的编程 我希望在运行时用户在SetInterval中更改TimeOut 更改Html标签输入中的值时 但是下面的代码不能正常工作 请帮帮我 问候Yarian < !DOCTYPE html > < html xmlns = http://www.w3.org/1999/xhtml > < head runat = 服务器 > < title > < / title > < script src = JS / jquery-2.1.3.js > < / script > < script type = text / javascript > $( document )。ready( function (){ var i = 0 ; var interval = 0 ; setInterval( function (){ document .getElementById( WRDO)。innerHTML =(i ++)。toString(); document .getElementById( WRDO1 ).innerHTML = document .getElementById( DO)。value.toString(); interval = parseInt ( document .getElementById( DO)。value.toString()); interval * = 1000 ; },interval); }); < / script > < / head > < body > < 输入 type = text id = DO 值 = 1 / > < p id = WRDO > < / p > < p id = WRDO1 > < / p > < / body > < / html > 我的尝试: 你好亲爱的编程 我希望在运行时用户在SetInterval中更改TimeOut 但是代码不能正常工作 请帮帮我 问候Yarian 解决方案 ( document )。ready( function (){ var i = 0 ; var interval = 0 ; setInterval( function (){ document .getElementById( WRDO)。innerHTML =(i ++)。toString(); document .getElementById( WRDO1 ).innerHTML = document .getElementById( DO)。value.toString(); interval = parseInt ( document .getElementById( DO)。value.toString()); interval * = 1000 ; },interval); }); < / script > < / head > < body > < 输入 type = text id = DO 值 = 1 / > < p id = WRDO > < / p > < p id = WRDO1 > < / p > < / body > < / html > 我的尝试: 你好亲爱的编程 我希望在运行时用户在SetInterval中更改TimeOut 但是代码不能正常工作 请帮帮我 问候Yarian 这是一团糟。你在哪里得到这段代码? 1.它被声明为HTML5 doctype但为什么同时 < html xmlns = http://www.w3.org/1999/xhtml > 2.有这个jQuery库,但你在jquery document.ready()方法中使用了普通的js代码。 读出: HTML教程 [ ^ ];和 jQuery教程 [ ^ ] 回到你的问题,如果你想要采取一些行动(例如将值间隔改为在文本框中)当某个事件发生时(例如,在文本框中更改值),您必须首先将该操作绑定到该事件。就像现在一样,他们没有受到约束。看看这些: JS onchange Event [ ^ ];或者 jQuery .change() [ ^ ] 更新间隔值后,清除当前计时器,然后启动计时器一个新的间隔,怎么办?问Google。 试试这个 < !DOCTYPE html > < html xmlns = http://www.w3.org/1999/xhtml > < head > < title > < / title > < script src = jquery-1.8.2.js > < / script > < script 类型 = text / javascript > Hello Dear ProgrammingI want Change TimeOut In SetInterval Of JavaScript By User In RunTimeWhen Changing Value In Tag Input Of HtmlBut Below Code Not Working TruePlease Help MeBy Regards Yarian<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script src="JS/jquery-2.1.3.js"></script> <script type="text/javascript"> $(document).ready(function () { var i = 0; var interval = 0; setInterval(function () { document.getElementById("WRDO").innerHTML = (i++).toString(); document.getElementById("WRDO1").innerHTML = document.getElementById("DO").value.toString(); interval = parseInt(document.getElementById("DO").value.toString()); interval *= 1000; }, interval); }); </script></head><body> <input type="text" id="DO" value="1" /> <p id="WRDO"></p> <p id="WRDO1"></p></body></html>What I have tried:Hello Dear ProgrammingI want Change TimeOut In SetInterval Of JavaScript By User In RunTimeBut Below Code Not Working TruePlease Help MeBy Regards Yarian 解决方案 (document).ready(function () { var i = 0; var interval = 0; setInterval(function () { document.getElementById("WRDO").innerHTML = (i++).toString(); document.getElementById("WRDO1").innerHTML = document.getElementById("DO").value.toString(); interval = parseInt(document.getElementById("DO").value.toString()); interval *= 1000; }, interval); }); </script></head><body> <input type="text" id="DO" value="1" /> <p id="WRDO"></p> <p id="WRDO1"></p></body></html>What I have tried:Hello Dear ProgrammingI want Change TimeOut In SetInterval Of JavaScript By User In RunTimeBut Below Code Not Working TruePlease Help MeBy Regards YarianThis is a mess. Where did you get this code?1. It is declared as HTML5 doctype but why at the same time <html xmlns="http://www.w3.org/1999/xhtml">2. There is this jQuery library, but you are using plain js code inside the jquery document.ready() method.Do read out:HTML Tutorial[^]; andjQuery Tutorial[^]Coming back to your question, if you want some action to take place (e.g changing the value interval to that in a text box) upon the happening of some event (e.g. changing of value in the text box), then you have to first bind that action to that event. As it is now, they are not bound. Check these out:JS onchange Event[^]; orjQuery .change()[^]After you have updated the interval value, clear the current timer, then start the timer with a new interval, how to do this? Ask Google.try this<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head > <title></title> <script src="jquery-1.8.2.js"></script> <script type="text/javascript"> 这篇关于我想在运行时由用户在javascript的setinterval中更改超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 12:34