一般这个场景适用于发送手机短信验证码,点击按钮弹出输入图像验证码
let mobile = $('#mobile').val();
if(mobile.length == 0){
layer.msg('手机号码不能为空', {icon:5, time: 2000, anim: 6});
return false;
}
if(!mobile_regexp.test(mobile)){
layer.msg('手机号码格式不对', {icon:5, time: 2000, anim: 6});
return false;
}
let _this = $(this);
layer.prompt({
title: '<img src="https://xxx.com/buildVerifyCode/sms" id="verifyImg" height="50">',
formType: 0,
move:false,
value: '', //初始时的值,默认空字符
maxlength: 140, //可输入文本的最大长度,默认500
success: function(layero, index){
layero.find('input').attr('placeholder',"请输入图形验证码");
$('.layui-layer-title img').css('cursor','crosshair');
layero.on('click','#verifyImg',function(){
let url=$(this).attr('src');
$(this).attr('src',url+"/"+(new Date()).valueOf());
});
}
}, function(value, index, elem){
let code=value;
if(code.length != 4){
layer.msg('验证码不正确', {icon:5, time: 2000, anim: 6});
return false;
}
$.post(
'/registerSendSMS',
{code: code, mobile: mobile},
function(response){
if(response.code == 1){
//这里写成功操作
layer.close(index);
}else{
//这里写失败操作
layer.msg(response.message, {icon: 5, time: 2000, anim:6});
return false;
}
}
);
});