h5发送验证码

html部分

<input class="code-input" type="tel" maxlength="6" placeholder="输入验证码" />
<button id="codeBtn" disabled="disabled">获取验证码</button>

js部分

			//发送验证码倒计时
			var countdown = 10;
			var obj = $("#codeBtn");
			$('#codeBtn').on('click', function() {
				settime(obj);
				console.log($("#mob").val())
				$.ajax({
					url: "http://dbs.app.douboshi.cn/App/Christmas/Index/sendSms", //请求的url地址
					dataType: "json", //返回格式为json
					async: true, //请求是否异步,默认为异步,这也是ajax重要特性
					data: {
						"phone": $("#mob").val()
					}, //参数值
					type: "post", //请求方式
					success: function(req) {
						//请求成功时处理
						if(req.success == true) {
							$('.error-small').html(req.msg);
							$(".error-small").show();
							$(".error-small").fadeOut(3000)
						} else {
							$('.error-small').html(req.msg);
							$(".error-small").show();
							$(".error-small").fadeOut(3000)

						}
					},
					error: function() {
						//请求出错处理
					}
				});
			})


			function settime(obj) {
				if(countdown == 0) {
					obj.attr('disabled', false);
					//obj.removeattr("disabled");
					obj.html("获取验证码");
					countdown = 10;
					return;
				} else {
					obj.attr('disabled', true);
					obj.removeClass('.text-red')
					obj.html(countdown);
					countdown--;
				}

				setTimeout(function() {
					settime(obj)
				}, 1000)
			}```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值