jq循环请求后端

一个非常简单的循环代码,点击开始和停止,支持自定义次数
<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|隐藏机器人聊天)
添加新回复
回复需要登录