var Common = {
//獲得url參數(例:"http://localhost:1239?a=1")
GetQueryString: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
//if (r != null) return unescape(r[2]); return null;
if (r != null) return decodeURI(r[2]); return null;
},
//回到頭部(參數爲距頂部的距離,默認沒有距離)
GoTop: function (marginTop) {
$('body,html').animate({ scrollTop: marginTop || 0 }, 500);
},
//回到尾部(參數爲距尾部的距離,默認沒有距離)
GoBottom: function (marginBottom) {
var sc = $(document).height() - (marginBottom || 0);
$('body,html').animate({ scrollTop: sc }, 500);
},
//獲得選擇器
ReturnObj: function (obj) {
try {
var object = typeof obj == "string" ? $("#" + obj).length ? $("#" + obj.replace("#", "")) : $("." + obj).length ? $("." + obj.replace(".", "")) : $(obj) : $(obj);
return object;
}
catch (e) {
return $(obj);
}
},
//切換驗證碼
ToggleCode: function (obj, codeurl) {
$(obj).children("img").eq(0).attr("src", codeurl + "?time=" + Math.random());
return false;
},
//四捨五入的函數
ForDight: function (Dight, How) {
//例:Common.ForDight(1.413, 1); 保留一位小數 結果爲1.4
Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
return Dight;
},
//toFixed() 方法可把 Number 四捨五入爲指定小數位數的數字
//eg:var num = new Number(1);alert(num.toFixed(2)); 結果爲1.00
ForFixed: function (num, obj) {
var num = new Number(num);
return num.toFixed(obj);
},
ForNumber: function (number) {
return number / 100;
},
//顯示信息
MyMsg: {
//成功提示
SuccessMsg: function (msg, showTime, successFunction) {
Common.MyMsg.ShowMsg(msg, 1, showTime, successFunction);
},
//錯誤提示
ErrorMsg: function (msg, showTime) {
Common.MyMsg.ShowMsg(msg, 2, showTime);
},
//顯示信息(icon 1爲成功,2爲失敗,3爲詢問,4爲鎖,5爲哭臉,6爲笑臉,7爲警告)
//至關於一個重載的方法 參數icon不傳入的話,就是沒有任何符號的提示
//如:Common.MyMsg.ShowMsg("真的",3,2000, a); a爲方法名 參數必需要齊全,少一個調用方法都會失敗
ShowMsg: function (msg, icon, time, successFunction) {
try {
layer.msg(msg, {
icon: icon,
time: time || 2000 //2秒關閉
}, successFunction);//提示後能夠執行特定的function
} catch (e) {
alert(msg || e.message);
}
},
},
//加載層
MyLoad: {
//load下標
LoadIndexs: null,
//顯示加載
ShowLoad: function () {
Common.LoadIndexs = Common.LoadIndexs || new Array();
try {
Common.LoadIndexs[Common.LoadIndexs.length] = layer.load(2);
//Common.LoadIndexs[Common.LoadIndexs.length] = layer.open({
// type: 3,
// shade: [0.4, '#000']
//});
}
catch (e)
{ }
},
//關閉全部層
CloseLoad: function () {
if (Common.LoadIndexs) {
$.each(Common.LoadIndexs, function (index, ele) {
layer.close(ele);
});
}
}
},
//能夠是輸入後驗證的錯誤提示
//msg提示信息 obj是選中的對象 如:按鈕、文本框等
MyTips: function (obj, msg) {
layer.tips(msg, obj, {
tips: [1, '#3595CC'],
time: 2000
});
},
//詢問框
MyConForm: function (msg, successFunction) {
try {
layer.confirm(msg, { icon: 3, title: "提示" }, function (index) {
successFunction();
layer.close(index);
});
}
catch (e) {
if (confirm(msg)) {
successFunction();
}
}
},
MyAjax: {
//發起ajax請求
Ajax: function (type, url, data, async, dataType, successFunction, isShowLoad) {
//彈出遮罩
//$(document).ajaxStart(function () {
// Common.MyLoad.ShowLoad();
//});
//關閉遮罩
$(document).ajaxStop(function () {
Common.MyLoad.CloseLoad();
});
//發起請求
$.ajax({
type: type,
url: url,
data: data, //$.extend(data, { M: Math.random() }),
global: isShowLoad,
async: async,//true 異步 默認值,false 同步
contentType: dataType,//dataType
success: successFunction,
error: Common.MyAjax.AjaxError
});
},
//發起ajaxPost請求,返回json
GetJsonByPost: function (url, data, async, successFunction, isShowLoad) {
Common.MyAjax.Ajax("POST", url, data, async, "application/json", successFunction, isShowLoad);
},
//發起ajaxGet請求,返回json
GetJsonByGet: function (url, data, async, successFunction, isShowLoad) {
Common.MyAjax.Ajax("GET", url, data, async, "application/json", successFunction, isShowLoad);
},
//發起ajaxPost請求,返回html
GetHtmlByPost: function (url, data, async, successFunction, isShowLoad) {
Common.MyAjax.Ajax("POST", url, data, async, "html", successFunction, isShowLoad);
},
//發起ajaxGet請求,返回html
GetHtmlByGet: function (url, data, async, successFunction, isShowLoad) {
Common.MyAjax.Ajax("GET", url, data, async, "html", successFunction, isShowLoad);
},
//ajax錯誤時調用
AjaxError: function (XMLHttpRequest, textStatus, errorThrown) {
//dialog({ title: '提示', content: "狀態:" + textStatus + ";出錯提示:" + errorThrown, okValue: '肯定', ok: function () { } }).showModal();
}
},
//操做cookies
MyCookie: {
//寫cookies(過時時間默認爲7天)
SetCookie: function (name, value, expiresDays) {
var exp = new Date();
expiresDays = expiresDays || 7;
exp.setTime(exp.getTime() + expiresDays * 24 * 60 * 60 * 1000);//";//
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/;";//domain=" + Common.DomainName.MaxName();//domain=testcubejoy.com
},
//讀取cookies
GetCookie: function (name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg)) {
return decodeURI(unescape(arr[2]));
//return unescape(arr[2]);
}
else
return null;
},
//刪除cookies
DelCookie: function (name) {
var exp = new Date();
exp.setTime(exp.getTime() - 8 * 24 * 60 * 60 * 1000);
var cval = Common.MyCookie.GetCookie(name);//";//
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + "; path=/;";//domain=" + Common.DomainName.MaxName();//domain=testcubejoy.com
//$.cookie("idphonemail", null);
},
DelDomainCookies: function (domain) {
var cookies = document.cookie.split(/; */);
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
if (cookie.indexOf(domain) != -1) {
var eqPos = cookie.indexOf("=");
var name = cookie.substr(0, eqPos);
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=" + domain;
}
}
}
},
MyVerification: {
//驗證數字
VerificationInt: function (value) {
var patrn = /^[0-9]{1,20}$/;
if (typeof value == "number") {
return true;
}
else if (typeof value == "string" && !patrn.test(value)) {
Common.MyMsg.ErrorMsg("請輸入正確的數字");
return false;
}
},
//驗證手機(參數1爲值,參數2爲是否顯示默認提示)
VerificationMobile: function (value, isShowMsg) {
var patrn = /^(13[0-9]|15[0|3|6|7|8|9]|18[0-9])\d{8}$/;
if (patrn.test(value)) {
return true;
}
else {
if (isShowMsg) {
Common.MyMsg.ErrorMsg("請輸入有效的手機號");
}
return false;
}
},
},
}
第一步
頁面須要引用此js
第二步
var loginJs = {
//登陸
goLogin: function () {
var _userinfo = { name: "夏小沫", pwd: "123" };
var _addinfo = { Country: "北京", Street: "上地三街" };
Common.MyAjax.GetJsonByPost("/myinfo/GetInfo", JSON.stringify({ userinfo: _userinfo, addinfo: _addinfo }), false, function (data) {
try {
alert(data);
} catch (e) {
alert(e.message);
}
});
},
}
這是調用common.js的方法,方法很簡單,common.js就至關於一個類,直接調取就能夠。
備註:
loginJs是一個新的Js,寫法可能和你的寫法不太同樣,不過沒有關係,換個寫法也是能夠的
function aa(){
Common.MyAjax.GetJsonByPost("/myinfo/GetInfo",JSON.stringify({userinfo: _userinfo, addinfo: _addinfo}),false,function(data){
alert(data);
})
}
<input type="text" id="filterName">
<div class="scope fr">
<div class="option">
<div>所有積分範圍</div>
<div>0-100積分</div>
<div>100-500積分</div>
<div>1000-5000積分</div>
<div>5000-10000積分</div>
<div>10000積分以上</div>
</div>
</div>
$(function(){
$("#filterName").keyup(function(){
$(".option div").hide().filter(":contains('"+($(this).val())+"')").show();
}).keyup();
$(".option div").click(function(){
var _txt=$(this).text();
$("#filterName").val(_txt);
})
})
一.Join 語法概念
Join 按照功能可分爲三大類:
left join (左鏈接) 即:取左邊表的所有數據,即便右邊表沒有對應的數據,也是會把左邊表的數據取出來,並返回
right join(右鏈接) 即:和left join 相反,取右邊表的所有數據。
inner join(內鏈接,也叫等值鏈接) 即:取兩個表中共同的數據,相似於數學中的交集。
二.Left Join
語句:select * from TableA left join TableB on TableA.orderid=TableB.orderid
結果說明:取TableA表中全部的記錄與匹配TableB表中的記錄,若是TableB中沒有匹配的數據,則返回null,返回的數據集個數是TableA表中的個數
返回的結果集如圖:
三.Inner Join
語句:select * from A inner join B on A.orderid=B.orderid
結果說明:inner join產生同時符合A和B的一組數據
返回結果集如圖:
四.Right Join
語句:select * from A right join B on A.orderid=B.orderid
結果說明:取TableB表中全部的記錄與匹配TableA表中的記錄,若是TableA中沒有匹配的數據,則返回null,返回的數據集個數是TableB表中的個數
返回結果如圖:嘻嘻,沒有現成的圖,就不整圖片啦,相信你會了解返回的數據集的