这个效果以前见过一回,现在有需要这个,请大家帮一下好吗?提供代码或提供网址都行的,谢谢!在文本框中输入手机号时,自动将号分段,如:输入13655556665 在框中提示136 5555 6665 这样的。如下图所示:

解决方案 »

  1.   

    哈,有40分,我回复,但结贴率不高呢。alert("13655556666".replace(/^\d{3}|\d{4}/g, "$& "))
      

  2.   

     protected void Button1_Click(object sender, EventArgs e)
        {
            string a = this.TB1.Text;
            string b = a.Substring(0, 3) + " " + a.Substring(3, 4) + " " + a.Substring(7, 4);
            this.TB2.Text = b;
        }
      

  3.   


    我的两帖在“Web 开发 HTML(CSS)”版块置顶,所以没有结。那个代码可以写详细一些吗?本人不懂JS。就是在文本框中输入时,在另一个层中提示分段。可以写个详细的页面吗?如果可以,本人再加分
      

  4.   


    你这个代码可以写全一点吗?可以附上html吗
      

  5.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
     </head> <body>
      <input type="text" value="" onkeyup="document.getElementById('msg').innerHTML = this.value.replace(/^\d{3}|\d{4}/g, '$& ')" />
      <div id="msg" style="font:bold 12pt 宋体;color:#ff0000"></div>
     </body>
    </html>
      

  6.   


    <script type="text/javascript">
    function js(x){
    switch(x.value.length){
    case 3:x.value+=" ";break;
    case 8:x.value+=" ";break;
    }
    }
      </script>
      <body>
    <input type="text" onkeyup="js(this);"/>
      </body>
      

  7.   

    再写个直接在文本框中自动分段的:<input type="text" onkeyup="this.value=this.value.replace(/^\d{3}(?=\d)|\d{4}(?=\d)/g, '$& ')">
      

  8.   

    再给你写个分段提示的:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <style>
    .o{position:absolute;left:300px;top:200px}
    #x{position:relative;left:0px;top:0px;width:155px;height:22px;color:red;font:bold 12pt 黑体;text-align:center;line-height:22px;-moz-border-radius:5px;-webkit-border-radius:5px;border:solid 1px red}
    #y{position:relative;left:25px;top:0px;width:0px;height:0px;border-top:solid 0px #fff;border-right:solid 5px #fff;border-bottom:solid 6px red;border-left:solid 5px #fff;}
    #d{position:relative;left:0px;top:2px;display:none}
    input:focus+#d, input:hover+#d{display:block;}
    </style>
    <div class="o">
    <input type="text" onkeyup="document.getElementById('x').innerHTML=this.value.replace(/^\d{3}|\d{4}/g,'$& ')">
    <div id="d">
    <div id="y"></div>
    <div id="x"></div>
    </div>
    </div>
      

  9.   

    上面没贴好,字串有断点,再贴:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <style>
    .o{position:absolute;left:300px;top:200px}
    #x{position:relative;left:0px;top:0px;width:155px;height:22px;color:red;font:bold 12pt 黑体;text-align:center;line-height:22px;-moz-border-radius:5px;-webkit-border-radius:5px;border:solid 1px red}
    #y{position:relative;left:25px;top:0px;width:0px;height:0px;border-top:solid 0px #fff;border-right:solid 5px #fff;border-bottom:solid 6px red;border-left:solid 5px #fff;}
    #d{position:relative;left:0px;top:2px;display:none}
    input:focus+#d, input:hover+#d{display:block;}
    </style>
    <div class="o">
    <input type="text" onkeyup="document.getElementById('x').innerHTML=this.value.replace(/^\d{3}|\d{4}/g,'$& ')">
    <div id="d">
    <div id="y"></div>
    <div id="x"></div>
    </div>
    </div>