【问题标题】:HTML - javascript count time elapsed from button activation and click on itHTML - javascript 计算按钮激活后经过的时间并单击它
【发布时间】:2015-04-28 15:27:41
【问题描述】:

我想创建一个带有文本字段和提交按钮的简单 html-javascript 页面。提交按钮必须每 5 分钟启用一次,然后您可以在字段中写一些内容并单击提交。单击提交,它显示从激活和提交经过了多少时间。谢谢

<html>

<body>
	
	
		<div id="main">
		
		<!-- Form -->
		<form id="form" action="/" method="post">
			
					<label>
					<span>Website:</span>
					<input placeholder="http://" type="url" tabindex="4" required>
				</label>
			</div>
			
			<div>
				<button name="submit" type="submit" id="submit">invia</button>
				<script type="text/javascript">
				document.getElementById('submit').disabled = true;
				setTimeout(function(){
				document.getElementById('submit').disabled = false;
				}, 2000);
				</script>
				<script type="text/javascript">
				var t0 = performance.now();
				var i=0;
				do
				{
					i++;
				} while document.getElementById('submit').click();
				var t1 = performance.now();
				var time= ( (t1 - t0) + " milliseconds.");
				document.getElementById('time').innerHTML = time;
				 </script>
				 </div>
				 <div id="time"></div>
		</form>
		<!-- /Form -->
		
		</div>
	

</body>
</html>

【问题讨论】:

  • 你试过了吗?添加您的源代码。
  • 你能告诉我们你的代码和你在哪里阻止
  • Inc 大规模投票。向我们展示你所做的事情。
  • 如果问题已解决:点击已解决问题答案旁边的勾号,请勿编辑问题。

标签: javascript html time counter


【解决方案1】:

查看WindowTimers.setInterval(),其中在定义的每 n 次调用函数/回调。

在您的情况下,按钮属性启用/禁用。

希望这会有所帮助。

【讨论】:

    【解决方案2】:
    problem solved.
    

    <html>
    <body>
    
    <div id="main">
    <!-- Form -->
    	<form id="form" action="/" method="post">
    <div>	
    		<label>
    			<span>Website:</span>
    			<input placeholder="http://" type="url" required>
    		</label>
    </div>
    			
    <div>
    		<input type="button" value="Invia" id="Invia" onclick="stopTimer()" />
    						
    		<script type="text/javascript">
    			document.getElementById('Invia').disabled = true;
    			setTimeout(function(){
    			document.getElementById('Invia').disabled = false;
    			document.getElementById('tempVar').value = Date.now();
    			}, 5000);
    			</script>
    		
    		<script>
    
    		var greeting;
    		
    		function timeGreeting()
    		
    		{
    		
    		greeting = performance.now();
    		
    		}
    		
    		timeGreeting();
    		
    		function stopTimer()
    		
    		{
    		var time = performance.now();
    		alert((time - greeting) + "ms");
    				
    		}		
    		</script>
    		<input type="button" value="Ricarica Pagina" onClick="document.location.reload(true)">
    		
    </div>
        </form>
    		<!-- /Form -->
    		
    </div>
    
    </body>
    </html>

    【讨论】:

    • 这读起来更像是一个找不同的游戏,而不是一个答案。你改变了什么?为什么会有帮助?
    猜你喜欢
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    相关资源
    最近更新 更多