在id为phone的元素失去焦点时进行手机号的验证 $#phoneblurfunction ififnull$thisval $#phone_msghtml手机号不能为空; else var $reg=^13456789d9$; if!$regtest$#phoneval
随机生成验证码的jQuery代码:
function generateCode(){ var code=""; for(var i=0;i<4;i++){ var randomNum=Math.floor(Math.random()*10); code+=randomNum; } return code; }
$("#code").val(generateCode());
验证码验证的jQuery代码:
$("#code").blur(function(){ if(ifnull($(this).val())){ $("#code_msg").html("验证码不能为空"); }else{ if($(this).val()!=$("#code").val()){ $("#code_msg").html("验证码错误!"); }else{ $("#code_msg").html("√").css("color","green"); } } });
相应的HTML代码:
原文地址: https://www.cveoy.top/t/topic/bWqI 著作权归作者所有。请勿转载和采集!