博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jqery前端验证码 --仿写
阅读量:4099 次
发布时间:2019-05-25

本文共 3116 字,大约阅读时间需要 10 分钟。

!-- Bootstrap core CSS-->

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

 

 

样式代码

<style type="text/css">

    body{
        margin: 0;
        padding: 0; 
    }     
    .modal_content{
        padding: 30px;
        display: flex;
        justify-content: center;
        flex-direction: column; 
    }
    
    .modal_content>div{
        margin-bottom: 20px;
    }
    .modal_content>h5:first-child{
        margin:30px 0px;
    }
    #dialog label{
         color: #666;
    }
    #phone1{
        display: block;
        width: 100%;
        height: 70px; 
        background: none;
        padding-top: 30px;    
        border: 0;
        outline:none;
        text-align: center;    
        margin-top: -30px; 
        font-size: 16px;
        border-bottom: 1px solid rgba(0,0,0,.2);
        border-radius: 0;
    }
    .code1{
        display: flex;
        flex-direction: row;
        justify-content: space-between;    
        width: 100%;
        height: 70px; 
        background: none; 
        padding-top: 30px;    
        margin-top: -30px; 
        font-size: 16px;
        border-bottom: 1px solid rgba(0,0,0,.2);
        border-radius: 0;
    }
    #code1{  
        width: calc(100% - 90px);
        height: 55px; 
        background: none; 
        padding-top: 20px;    
        border: 0;
        outline:none;
        text-align: center;    
        margin-top: -20px; 
        font-size: 16px;  
    }
    #btnSendCode1{
        width: 90px;
        height: 30px;  
        padding: 0 5px;
        margin: 0;
        font-size: 14px;
        text-align: center;
        background: transparent;
        border-radius: 30px;
        color: #a07941;
        border-color: #a07941;
         
    }
    ::-webkit-input-placeholder { /* WebKit browsers */
        font-size: 14px;
        color:   rgba(0,0,0,.4);
    }
    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
        font-size: 14px;
        color:   rgba(0,0,0,.4);
    }
    ::-moz-placeholder { /* Mozilla Firefox 19+ */
        font-size: 14px;
        color:  rgba(0,0,0,.4);
    }
    :-ms-input-placeholder { /* Internet Explorer 10+ */
        font-size: 14px;
        color:   rgba(0,0,0,.4);
    }
        
    .next{
        text-align: center;
        margin: 20px 0;
    }
    .next button{
        width: 100%; 
        height: 45px;
        padding: 0;
        margin: 0;
        background: #007BFF;
        color: #fff;
        border: 0;
        outline:none;
        border-radius: 3px;
    }        
</style>

htm

<div class="modal_content">        

    <h5>绑定用户信息!</h5>
    <div>
        <label for="phone1">注册手机号:</label><br />
        <input id="phone1" type="text" autocomplete="off" placeholder="请输入已绑定的手机号">                
    </div> 
    <div>
        <label for="code1">验证码:</label>
        <div class="code1">
            <input id="code1" type="text" autocomplete="off" placeholder="短信验证码">                
            <input id="btnSendCode1" type="button" class="btn btn-default" value="获取验证码" onClick="sendMessage1()" />
        </div>                
    </div>     
    <div class="next">              
        <button onClick="binding()">确定</button>
    </div>
</div>         

 

js

var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;//手机号正则 

    var count = 60; //间隔函数,1秒执行
    var InterValObj1; //timer变量,控制时间
    var curCount1;//当前剩余秒数
    /*第一*/
    function sendMessage1() {
        curCount1 = count;                  
        var phone = $.trim($('#phone1').val());
        if (!phoneReg.test(phone)) {
            alert(" 请输入有效的手机号码"); 
            return false;
        }
        //设置button效果,开始计时
        $("#btnSendCode1").attr("disabled", "true");
        $("#btnSendCode1").val( + curCount1 + "秒再获取");
        InterValObj1 = window.setInterval(SetRemainTime1, 1000); //启动计时器,1秒执行一次
        //向后台发送处理数据
             
    }
    function SetRemainTime1() {
        if (curCount1 == 0) {                
            window.clearInterval(InterValObj1);//停止计时器
            $("#btnSendCode1").removeAttr("disabled");//启用按钮
            $("#btnSendCode1").val("重新发送");
        }
        else {
            curCount1--;
            $("#btnSendCode1").val( + curCount1 + "秒再获取");
        }
    } 
    
    /*提交*/
    function binding(){
        alert(1)
    }

转载地址:http://mhrii.baihongyu.com/

你可能感兴趣的文章
Piper Sandler为EverArc收购Perimeter Solutions提供咨询服务
查看>>
Wipro加入世界经济论坛“新型工作标准伙伴关系”倡议
查看>>
RMRK筹集600万美元,用于在Polkadot上建立先进的NFT系统标准
查看>>
巴西试点全球首个采用面部识别技术的穿梭航班服务
查看>>
Bentley 软件公司完成对全球领先的地球科学三维建模软件提供商 Seequent 的收购
查看>>
Pattern Computer研制出高准确度新冠肺炎检测系统,15秒可出结果
查看>>
东芝董事长发布致股东公开信
查看>>
zooom Productions选择Esri的ArcGIS Platform,打造红牛X-Alps穿越赛实时跟踪应用
查看>>
由EIG牵头的财团与沙特阿美达成124亿美元的基础设施交易
查看>>
法拉利选择AWS作为其官方云提供商,助力公路和赛道创新
查看>>
泰雷兹为物联网连接带来变革,以“即开即用”的方式连接至全球任意蜂窝网络
查看>>
ABLIC推出业界超小型(*1)车载用高侧开关S-19682/3系列 具摄像头/天线连接诊断功能
查看>>
Elliptic Labs与博世旗下的Grow平台签署许可协议
查看>>
沙迦表彰肯尼亚人道主义机构RefuSHE在儿童和女童难民救助方面所做的开拓性贡献
查看>>
MulteFire Alliance (MFA)简化企业5G专用网络的部署途径
查看>>
希尔顿旗下多家品牌酒店重返拉斯维加斯,通过快速扩张加倍押注赌城未来
查看>>
乐高®跨界联动全新百老汇音乐剧,隆重揭幕纽约第五大道最新创意门店
查看>>
Zain Iraq通过MATRIXX Software推出突破性数字品牌oodi
查看>>
NetApp收购Data Mechanics,将加速Spot发展并优化云端数据分析和机器学习工作负载
查看>>
LegoChem Biosciences与Iksuda Therapeutics扩大抗体药物偶联物开发许可协议
查看>>