<script type="text/javascript" src="query.js" ></script>
<script>
var tel;
var ajax=function(){
//淘宝接口
$.ajax({
type: "get",
url: 'http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel='+tel,
dataType: "jsonp",
jsonp: "callback",
success: function(data){
console.log(data);
$('.error').css('display','none');
var province = data.province,
operators = data.catName,
num = data.telString;
$('.num span').html(num);
$('.province span').html(province);
$('.operators span').html(operators);
},
error:function (){
$('li span').html('');
$('.error').css('display','block');
}
});
}
var reg = /^(13|15|18)[0-9]{9}$/;//点击查询
$('.button').click(function(){
tel=$('input[type=text]').val();
if(tel){
if(reg.test(tel)){
ajax();
}else{
$('li span').html('');
$('.error').css('display','block');
}
}
});
//键盘事件
$(window).keydown(function(event){
tel=$('input[type=text]').val();
if(event.keyCode==13) {
if(tel){
if(reg.test(tel)){
ajax();
}else{
$('li span').html('');
$('.error').css('display','block');
}
}
}
});
</script>
新闻热点
疑难解答