项目案例需求如,输入/绑定正确的手机号才能下载软件,输入手机号发送验证码的功能等;
如下代码可以实现基本功能:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> .gray-btn{ background: #ccc; } .blue-btn{ background: #09f; } </style> </head> <body> <input type="tel" name="mobile" id="getNum" value="" placeholder="填写手机号码" autocomplete=‘off‘/> <input type="button" name="button" class="gray-btn downloadBtn" value="去下载**APP" disabled/> <script src="jquery-1.7.2.min.js"></script> <script> //监听输入手机号 $(document).on(‘input propertychange‘,‘#getNum‘,function (e) { if (e.type === "input" || e.orignalEvent.propertyName === "value") { if(this.value.length == 11){ var myreg = /^1\d{10}$/; if(!myreg.test(this.value)){ common.tips({msg:‘请输入正确手机号‘}); return; } $(‘.downloadBtn‘).removeClass(‘gray-btn‘).addClass(‘blue-btn‘); $(‘.downloadBtn‘).attr("disabled", false); }else{ $(‘.downloadBtn‘).addClass(‘gray-btn‘).removeClass(‘blue-btn‘); $(‘.downloadBtn‘).attr("disabled", true); } } }) </script> </body> </html>
时间: 2024-10-05 12:40:11