bob体育官方平台
bob体育官方平台jquery+ajax+text文本框实现智能提示完整实例_jquery_脚本之家

本文实例汇总了基于jQuery的项目常见函数封装。分享给大家供大家参考,具体如下:

本文实例讲述了jquery+ajax+text文本框实现智能提示的方法。分享给大家供大家参考,具体如下:

/// /** DIV或元素居中* @return*/jQuery.fn.mCenterDiv = function () { this.css("position", "absolute"); this.css("border", "1px solid #ccc"); this.css.height / 2 + $ + "px"); this.css.width / 2 + $ + "px"); this.show; return this;};/** 替换字符串中所有符合的字符* @param ASource 源字符串* @param AFindText 待替换字符* @param ARepText 替换后字符* @return*/jQuery.mReplaceAll = function (ASource,AFindText, ARepText) { var raRegExp = new RegExp; return ASource.replace;};/** 判断object是否空,未定义或null* @param object* @return*/jQuery.mIsNull = function  { if (obj == "" || typeof == "undefined" || obj == null) { return true; } else { return false; }};/** 获取URL参数* @param name 参数* @return*/jQuery.mGetUrlParam = function  { var reg = new RegExp" + name + "=; var r = window.location.search.substr; if  return unescape; return null;};/** 乘法函数,用来得到精确的乘法结果* @param arg1 参数1* @param arg2 参数2* @return*/jQuery.mAccMul = function { var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); try { m += s1.split[1].length } catch  { } try { m += s2.split[1].length } catch  { } return Number * Number / Math.pow}/** 获取随机数* @param x 下限* @param y 上限* @return*/jQuery.mGetRandom = function  { return parseInt * ;};/** 将数值四舍五入后格式化成金额形式* @param num 数值* @return 金额格式的字符串,如'1,234,567.45'*/jQuery.mFormatCurrency = function { num = num.toString().replace; if  num = "0"; sign = (num == ; num = Math.floor(num * 100 + 0.50000000001); cents = num % 100; num = Math.floor; if  cents = "0" + cents; for (var i = 0; i < Math.floor) / 3); i++) num = num.substring(0, num.length -  + ',' + num.substring(num.length - ; return  ? '' : '-') + num + '.' + cents);}/** 正则验证* @param s 验证字符串* @param type 验证类型 money,china,mobile等* @return*/jQuery.mCheck = function  { var objbool = false; var objexp = ""; switch  { case 'money': //金额格式,格式定义为带小数的正数,小数点后最多三位 objexp = "^[0-9]+[.][0-9]{0,3}$"; break; case 'numletter_': //英文字母和数字和下划线组成 objexp = "^[0-9a-zA-Z_]+$"; break; case 'numletter': //英文字母和数字组成 objexp = "^[0-9a-zA-Z]+$"; break; case 'numletterchina': //汉字、字母、数字组成 objexp = "^[0-9a-zA-Zu4e00-u9fa5]+$"; break; case 'email': //邮件地址格式 objexp = "^+@++$"; break; case 'tel': //固话格式 objexp = /^??[1-9]d{6,7}?$/; break; case 'mobile': //手机号码 objexp = "^(13[0-9]|15[0-9]|18[0-9])$"; break; case 'decimal': //浮点数 objexp = "^[0-9]+?$"; break; case 'url': //网址 objexp = "{0,1}[w/.?&=]+"; break; case 'date': //日期 YYYY-MM-DD格式 objexp = /^$/; break; case 'int': //整数 objexp = "^[0-9]*[1-9][0-9]*$"; break; case 'int+': //正整数包含0 objexp = "^\d+$"; break; case 'int-': //负整数包含0 objexp = "^$"; break; case 'china': //中文 objexp = /^[u0391-uFFE5]+$/; break; } var re = new RegExp; if  { return true; } else { return false; }};/** 获取控件的值* @param controlID 控件ID* @param controltype 类型 如text radio* @return*/jQuery.mGetValue = function (controlID, controltype) { var objValue = ""; switch  { case 'text': //文本输入框 objValue = $.trim($.attr; //取值去左右空格 break; case 'radio': //单选框 objValue = $("input[name='" + controlID + "']:checked").attr; break; case 'select': //下拉列表 objValue = $.attr; break; case 'checkbox': //多选框 $("input[name='" + controlID + "']:checked").each { objValue += $; break; default: break; } return objValue;};/** 设置控件的值* @param controlID 控件ID* @param controltype 类型 如text radio* @param controlvalue 绑定值* @return*/jQuery.mSetValue = function (controlID, controltype, controlvalue) { switch  { case 'text': //文本输入框 //$.attr; //填充内容 //$("input[name='radio1'][value='上海']").attr; //单选组radio:设置value='上海'的项目为当前选中项 //$.attr; //下拉框select:设置value='中国'的项目为当前选中项 //$("input[name='checkbox1'][value='黑色'],[value='蓝色']").attr; //多选框:设置多个值为当前选中项 $.attr("value", controlvalue); //填充内容 break; case 'radio': //单选框 $("input[name='" + controlID + "'][value='" + controlvalue + "']").attr; break; case 'select': //下拉列表 $.attr("value", controlvalue); break; case 'checkbox': //多选框 $("input[name='" + controlID + "'][value='" + controlvalue + "'],[value='" + controlvalue + "']").attr; //多选框:设置多个值为当前选中项 break; default: break; }};/** 兼容IE火狐等浏览器的自动跳转* @param url 跳转网址* @return*/jQuery.mAutoNav = function  { if  { var referLink = document.createElement; referLink.href = url; document.body.appendChild; referLink.click(); } else { location.href = url; }};/** Table表格奇偶行设置颜色及移动鼠标行变色* @param table 表格ID* @return*/jQuery.mTableHover = function  { $.each { var o = $; //设置偶数行和奇数行颜色 o.find.css("background-color", "#EFF3FB"); o.find.css("background-color", "#FFFFFF"); //鼠标移动隔行变色hover用法关键 o.find.hover.attr.css.css("background-color", "#E0E0E0"); }, function .css("background-color", $; }); });};/** gridview 隔行换色 鼠标滑过变色 多选* c#获取选择值 Request.Form.Get* @param objgridview ID* @return*/jQuery.mGridview = function  { var headcolor = { background: '#E0ECFF', color: '#333' }; var normalcolor = { background: '#f7f6f3' }; var altercolor = { background: '#EDF1F8' }; var hovercolor = { background: '#89A5D1' }; var selectcolor = { background: '#ACBFDF' }; var nullcolor = {}; //get obj id var gridviewId = "#" + objgridview; //even $(gridviewId + ">tbody tr:even").css; //first $(gridviewId + ">tbody tr:first").css.css; //odd $(gridviewId + ">tbody tr:odd").css; //hover $(gridviewId + ">tbody tr").click { var cb = $.find; var chf = typeof  == "undefined" ? true : false; cb.attr; var expr1 = gridviewId + ' >tbody >tr >td >input:checkbox:checked'; var expr2 = gridviewId + ' >tbody >tr >td >input:checkbox'; var selectAll = $.length == $.length; $.attr; }).hover.css; }, function () { $(gridviewId + ">tbody tr:even").css; $(gridviewId + ">tbody tr:first").css.css; $(gridviewId + ">tbody tr:odd").css; //all check $.click { $(gridviewId + '>tbody >tr >td >input:checkbox:visible').attr('checked', this.checked); }); //check status $(gridviewId + ' >tbody >tr >td >input:checkbox').click { var cb = $; var chf = typeof  == "undefined" ? true : false; cb.attr; var expr1 = gridviewId + ' >tbody >tr >td >input:checkbox:checked'; var expr2 = gridviewId + ' >tbody >tr >td >input:checkbox'; var selectAll = $.length == $.length; $.attr; });};/** 屏幕居中显示处理进度* @param info 显示文字* @param type 方式 0遮罩 1不遮罩* @param typepic 图片 0:load 1:ok 2:error* @return*/jQuery.mMaskLoad = function  { var pic = ""; switch  { case 0: // loading pic = "./Images/loading.gif"; break; case 1: // ok pic = "./Images/right.png"; break; case 2: // error pic = "./Images/error.png"; break; default: //其他任何值时 pic = "./Images/loading.gif"; break; } if  { $("").css( { display: "block", width: "100%", position: "absolute", left: "0", top: "0", opacity: "0.3", height: "100%", filter: "alpha", background: "#ccc" }).appendTo; }; $("").css( { position: "absolute", top: "50%", padding: "12px 5px 10px 30px", width: "auto", height: "16px", border: "1px solid #D1D1D1", background: "#ffffff url no-repeat scroll 5px center", display: "block", left: .outerWidth / 2, top:  - 45) / 2 }).html.appendTo;};/** 屏幕居中隐藏处理进度* @return*/jQuery.mMaskLoadClose = function () { $.remove(); $.remove();};/** 控件后创建SPAN作为TIP提示* @param o 用this* @param tip 提示文字* @param typepic 图片 0:load 1:ok 2:error* @return*/jQuery.mTip = function  { var pic = ""; switch  { case 0: // loading pic = "./Images/loading.gif"; break; case 1: // ok pic = "./Images/right.png"; break; case 2: // error pic = "./Images/error.png"; break; default: //其他任何值时 pic = "./Images/loading.gif"; break; } var eTip = document.createElement; var objid = $ + "_tipDiv"; var value = $; //绝对路径 var x = $.top; var y = $.left; var w = $; var h = $; eTip.setAttribute; try { document.body.appendChild { } $; $.css({ top: x, left: y + w + 10, height: h, position: "absolute" }); $.html("" + tip); $;};/*** ajax post提交* @param url* @param param* @param datat 为html,json,text* @param callback 回调函数 function callBack* @return*/jQuery.mJqAjax = function (url, param, datat, callback) { $.ajax({ type: "post", url: url, data: param, dataType: datat, success: callback, error: function ;};

/// /*********************************************************************//***************************Jquery 扩展****************************//*********************************************************************/jQuery.mIsNull = function  { if (obj == "" || typeof  == "undefined" || obj == null) { return true; } else { return false; }};jQuery.mCheckNull = function (id, tipid, nullmess, ctype) { var str = $.mGetValue; var tid =  ? id : tipid; var obj =  ? $.mTip : $.mTipCustom; if  { obj("#" + tid, nullmess, 2); } else { obj; }};jQuery.mCheckNullAndReg = function (id, tipid, nullmess, regmess, ctype, rtype) { var str = $.mGetValue; var tid =  ? id : tipid; var obj =  ? $.mTip : $.mTipCustom; if  { obj("#" + tid, nullmess, 2); } else { if  { obj; } else { obj("#" + tid, regmess, 2); } }};jQuery.mCheck = function  { var objbool = false; var objexp = ""; switch  { case 'money': //金额格式,格式定义为带小数的正数,小数点后最多三位 objexp = "^[0-9]+[.][0-9]{0,3}$"; break; case 'numletter_': //英文字母和数字和下划线组成 objexp = "^[0-9a-zA-Z_]+$"; break; case 'numletter': //英文字母和数字组成 objexp = "^[0-9a-zA-Z]+$"; break; case 'numletterchina': //汉字、字母、数字组成 objexp = "^[0-9a-zA-Zu4e00-u9fa5]+$"; break; case 'email': //邮件地址格式 objexp = "^+@++$"; break; case 'tel': //固话格式 objexp = /^??[1-9]d{6,7}?$/; break; case 'mobile': //手机号码 objexp = "^(13[0-9]|15[0-9]|18[0-9])$"; break; case 'decimal': //浮点数 objexp = "^[0-9]+?$"; break; case 'url': //网址 objexp = "{0,1}[w/.?&=]+"; break; case 'date': //日期 YYYY-MM-DD格式 objexp = /^$/; break; case 'int': //整数 objexp = "^[0-9]*[1-9][0-9]*$"; break; case 'int+': //正整数包含0 objexp = "^\d+$"; break; case 'int-': //负整数包含0 objexp = "^$"; break; case 'china': //中文 objexp = /^[u0391-uFFE5]+$/; break; } var re = new RegExp; if  { return true; } else { return false; }};jQuery.mTip = function  { var pic = ""; switch  { case 0: // loading pic = "/images/publicNew/loading.gif"; break; case 1: // ok pic = "/images/publicNew/right.png"; break; case 2: // error pic = "/images/publicNew/error.png"; break; default: //其他任何值时 pic = "/images/publicNew/onLoad.gif"; break; } var eTip = document.createElement; var objid = $ + "_tipDiv"; var value = $; //绝对路径 var x = $.top; var y = $.left; var w = $; var h = $; eTip.setAttribute; try { document.body.appendChild { } $; $.css({ top: x, left: y + w + 10, height: h, position: "absolute" }); $.html("" + tip); $;};jQuery.mTipCustom = function  { var pic = ""; switch  { case 0: // loading pic = "/images/publicNew/loading.gif"; break; case 1: // ok pic = "/images/publicNew/right.png"; break; case 2: // error pic = "/images/publicNew/error.png"; break; default: //其他任何值时 pic = "/images/publicNew/onLoad.gif"; break; } $.html("" + tip); $;};jQuery.mGetValue = function (controlID, controltype) { var objValue = ""; switch  { case 'text': //文本输入框 objValue = $.trim($.attr; //取值去左右空格 break; case 'radio': //单选框 objValue = $("input[name='" + controlID + "']:checked").attr; break; case 'select': //下拉列表 objValue = $.attr; break; case 'checkbox': //多选框 $("input[name='" + controlID + "']:checked").each { objValue += $; break; default: break; } return objValue;};/*** ajax post提交* @param url* @param param* @param datat 为html,json,text* @param callback 回调函数 function callBack* @return*/jQuery.mJqAjax = function (url, param, datat, callback) { $.ajax({ type: "post", url: url, data: param, dataType: datat, success: callback, error: function ;};

模仿百度查询的智能提示

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《jQuery表格操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》

 #searchresult { width: 130px; position: absolute; z-index: 1; overflow: hidden; left: 130px; top: 71px; background: #E0E0E0; border-top: none; } .line { font-size: 12px; background: #E0E0E0; width: 130px; padding: 2px; } .hover { background: #007ab8; width: 130px; color: #fff; } .std { width: 150px; }

希望本文所述对大家jQuery程序设计有所帮助。

jquery代码部分:

上一篇:没有了 下一篇:bob体育appjs中forEach、for-in和for-of循环方法
返回顶部