js實現顯示手機號碼效果,js實現手機號碼

來源:互聯網
上載者:User

js實現顯示手機號碼效果,js實現手機號碼

:

代碼如下:

<!doctype html><html><head><meta charset="utf-8"><title>telephone number</title><style>*{    margin:0;    padding:0;}form{    width:300px;    position:relative;    margin:10px;}fieldset{    padding:10px;    border:1px dashed #ddd;}#num_info{    display:none;    position:absolute;    left: 11px;    bottom: 37px;    width: 170px;    height:30px;    border:1px solid #ddd;    border-bottom:none;    background-color:#f6f6f6;    font:20px/30px verdana,arial;    color:#F90;    }#num{    width:170px;    height:24px;    line-height:24px;    margin-top:40px;    border:1px solid #bbb;}#num:focus{    outline:none;    border-color:#999;}p{    font-size:12px;    color:#999;}</style></head><body><form>    <fieldset>        <label id="num_info" for="num"></label>        <input type="text" id="num" maxlength="11">    </fieldset></form><script>window.onload=function(){    var $numInfo=document.getElementById('num_info'),        $num=document.getElementById('num'),        _val,_val1,_val2;    $num.onkeyup=function(){        var val=this.value=this.value.replace(/[^\d]/g,''),            len=val.length;            if(val!=''){$numInfo.style.display='block';}        if(len<=3){            _val=_val1= val.substr(0,3);        }        else if(len>3&&len<=7){            _val=_val2=_val1+"-"+val.substr(3,len);        }        else if(len>7){            _val=_val2+'-'+val.substr(7,len);        }        $numInfo.innerHTML=_val;    }    $num.onblur=function(){        $numInfo.style.display='none';            }}</script></body></html>

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的協助,同時也希望多多支援幫客之家!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.