基于jquery用于查询操作的实现代码

2020-05-22 21:55:42易采站长站整理



这是因为没有为InitBind()方法添加一个方法参数,这个参数能在不改变InitBind()方法的情况下进行一个操作内容的扩展。将代码还原。
 


f.SearchApply方法第一个参数是‘#’加上一个操作按钮的id(Search类会为该按钮添加回车事件),第二个参数是页面定向的url地址。
五 代码
tools.js

//工具类
function Tool() {
//字符串的替换格式化 (‘a{0}c{1}’,’b’,’d’)=> abcd
this.FormatStr = function(str, ary) {
for (var a in ary) {
str = str.replace(‘{‘ + a + ‘}’, ary[a]);
}
return str;
}
//字符串不为空
this.IsNoNullOrEmpty = function(str) {
if (typeof (str) == “undefined” || str == null || str == ” || str == ‘undefined’) {
return false;
}
else {
return true;
}
}
//得到URL参数
this.GetUrlParms = function() {
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split(“&”);
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf(‘=’);
if (pos == -1) continue;
var argname = pairs[i].substring(0, pos);
var value = pairs[i].substring(pos + 1);
args[argname] = unescape(value);
}
return args;
}
//查找字符串中需要字符的位置,isCase = true 表示忽略大小写
this.FindStr = function(str, findStr, isCase) {
if (typeof (findStr) == ‘number’) {
return str.indexOf(findStr);
}
else {
var re = new RegExp(findStr, isCase ? ‘i’ : ”);
var r = str.match(re);
return r == null ? -1 : r.index;
}
}
//查找字符串找是否存在相应的字符 isCase = true 表示忽略大小写
this.IsFindStr = function(str, findStr, isCase) {
return this.FindStr(str, findStr, isCase) > 0 ? true : false;
}
//验证短日期2010-2-2
this.IsShortTime = function(str) {
var r = str.match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2})$/);
if (r == null) return false;
var d = new Date(r[1], r[3] – 1, r[4]);
return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
}
}

search.js

function Search(initCss) {
this._Tool = new Tool();
this._UrlParmAry = { way: ‘way’, query: ‘query’, date: ‘date’, me: ‘me’, bdate: “bdate”, edate: “edate” };
this._UrlHtmlIdAry = { way: ‘#dropWay’, query: ‘#txtQuery’, date: ‘#txtDate’, me: ‘#cbShowMe’, bdate: “#txtDateBegin”, edate: “#txtDateEnd” };
this._DateInitStr = ‘xxxx-xx-xx’;