已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > HTML/CSS/JS > 教程

标题: jq循环请求后端

作者: @Ta

时间: 2020-11-21

点击: 3246

一个非常简单的循环代码,点击开始和停止,支持自定义次数
<html>
<head>
	<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script>
	$(function() {
		function test(){
			$(".test").append("|->");
			/*
				$.ajax({
				url:"/123.php",
				type:"get",
				timeout:"15000",
				async:true,
					success:function(data){
						$(".test").append(data);
					}
				})
			*/
		}
		$(".star").click(function(){
			num = $('.num').val();
			timer = setInterval(function() {
					test();
				if (num){
					num--;
					if (num <= 0) clearInterval(timer);
				}
				}, 1000);
				
		})
		$(".stop").click(function(){
			clearInterval(timer);
		})
	})
	</script>
</head>
<body>
<input type="text" class="num" size="5">
<button class="star">开始</button><button class="stop">停止</button>
<div class="test"></div>
</body>

</html>

[隐藏样式|查看源码]


『回复列表(2|隐藏机器人聊天)』

1. 666
(/@Ta/2020-11-21 12:20//)

3.
(/@Ta/2020-11-21 12:53//)

回复需要登录

6月28日 21:38 星期六

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1