jquery-判断手机号运营商

<!DOCTYPE>

<html>

 <head>

  <title> New Document </title>

  <meta charset="UTF-8">

  <meta name="Generator" content="EditPlus">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

  <link rel="stylesheet" type="text/css" href="">

  <script type="text/javascript" src="jquery.js">

  </script>

  <style type="text/css">

    div{color:red;height:25px;border:1px solid #000;line-height:25px;}

  </style>

 </head>



 <body>

 <input type="text" class="shuru">

 <div class="hao_div"></div>

 <div class="operator">为了练习,手机号只有138,133,131号段</div>

 </body>

 <script type="text/javascript">

 <!--

    var $oper_tex=$(".operator");

    $(".shuru").keyup(function(){        

        var $inp_val = $(".shuru").val();

            $(".hao_div").text($inp_val); 

            var $haoduan =  $inp_val.substring(0,3); //获取手机号前三位

            if ($inp_val.length == 11)

            {

                test2($haoduan);

            }

            else if ($inp_val.length > 11)

            {

                $oper_tex.text("请输入正确手机号码")

            }

            else if ($inp_val == "")

            {

                 $oper_tex.text("")

            }

    });

    function test2(zhi){

        var haoduan = {

            "138":"1", //中国移动

            "131":"2", //中国联通

            "133":"3"  //中国电信

        }

        switch (haoduan[zhi])

        {

         case "1":

         $oper_tex.text("中国移动");

         break;

         case "2":

         $oper_tex.text("中国联通");

         break;

         case "3":

         $oper_tex.text("中国电信");

         break;

        }

    }

 //-->

 </script>

</html>

 

你可能感兴趣的:(jquery)