-
-
Lowell_hao
2016-05-04
- sprint,占位符替换;http_build_query,将数据拼接为字符串
-
0赞 · 0采集
-
-
UncleLee
2016-03-29
- JS代码模块化形式输出
-
0赞 · 0采集
-
-
UncleLee
2016-03-29
- Js 赋值 类似三目方式
-
0赞 · 0采集
-
-
林静听蝉
2016-03-05
- base.js
$(document).ready(function(){
$('#query').click(function(){
//点击查询获取输入框的电话号码
var phone = $('#phone-num').val();
if (phone.length == 11) {
IMOOC.GLOBAL.AJAX('api.php','post',{'tel':phone},'json',IMOOC.APPS.QUERYPHONE.AJAXCALLBACK);}
});});
//定义一个对象
var IMOOC = IMOOC || {};//如果IMOOC存在就赋值给它,如果不存在就赋值一个空对象
//再定义2个子对象
IMOOC.GLOBAL = {};//一些ajax或app在页面中公用的js方法写在GLOBAL里
IMOOC.APPS = {};//针对某个APP,比如以后再扩展其它应用还要写js块就在这个APP里扩展
//定义归属地查询的callback
IMOOC.APPS.QUERYPHONE = {};
IMOOC.APPS.QUERYPHONE.AJAXCALLBACK = function(data){
if (data.code == 200) {IMOOC.APPS.QUERYPHONE.SHOWINFO();
}else{IMOOC.APPS.QUERYPHONE.HIDEINFO();
alert(data.msg);}};
//定义显示信息的方法
IMOOC.APPS.QUERYPHONE.SHOWINFO = function(){
$('#info').show();};
//定义隐藏信息的方法
IMOOC.APPS.QUERYPHONE.HIDEINFO = function(){
$('#info').hide();};
//封装Ajax请求的方法
IMOOC.GLOBAL.AJAX = function(url,method,params,dataType,callback){
$.ajax({url: url,type: method,data: params,dataType: dataType,success: callback,
error: function(){alert('请求异常');}});};
-
截图
0赞 · 0采集
-
-
林静听蝉
2016-03-05
- index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>手机归属地查询</title>
<script src="static/js/jquery.min.js"></script>
<script src="static/js/base.js"></script>
<link rel="stylesheet" href="static/css/bootstrap.min.css"/>
<link rel="stylesheet" href="static/css/flat-ui.css"/>
<style>
body {max-width: 720px;margin: 0 auto;}
.top-20 {margin-top: 20px;}
.table-width {margin-left: 20px;width: 95%;}
#info {display: none;}
</style>
</head>
<body>
<div class="row top-20">
<div class="col-xs-9">
<input type="text" id="phone-num" class="form-control"/>
</div>
<div class="col-xs-3">
<button class="btn btn-lg btn-block btn-primary" id="query">查询</button>
</div>
</div>
<div class="row top-20" id="info">
<table class="table table-width table-responsive">
<tr><th>手机号码</th><td id="query-tel">15933643352</td></tr>
<tr><th>归属地</th><td id="query-pro">北京</td></tr>
<tr><th>运营商</th><td id="query-cat">中国移动</td></tr>
<tr><th>其他</th><td id="query-other">慕课网</td></tr>
</table>
-
截图
0赞 · 0采集