通过jQuery打造支持汉字

2019-11-27 06:03栏目:网站首页
TAG:

复制代码 代码如下: //潇湘博客 // //PHP 技术群:37304662 //时间:2010-06-13 //版本 v3.0.0.0 //任意字符、中文与拼音综合查询 //方向键选择option //优化下拉框显示效果 //jquery超级select插件 $.fn.selectseach = function() { String.prototype.trim = function() { return this.replace; } //汉字转拼音 function makePy { if != "string") { return str; //throw new Error; } var arrResult = new Array(); for (var i = 0, len = str.length; i < len; i++) { var ch = str.charAt; arrResult.push; } var resarr = mkRslt; return resarr.join; } function checkCh { var uni = ch.charCodeAt; if (uni > 40869 || uni < 19968) return ch; //dealWithOthers; return (oMultiDiff[uni] ? oMultiDiff[uni] : (strChineseFirstPY.charAt; } function mkRslt { var arrRslt = [""]; for (var i = 0, len = arr.length; i < len; i++) { var str = arr[i]; var strlen = str.length; if { for (var k = 0; k < arrRslt.length; k++) { arrRslt[k] += str; } } else { var tmpArr = arrRslt.slice; arrRslt = []; for (k = 0; k < strlen; k++) { var tmp = tmpArr.slice; for (var j = 0; j < tmp.length; j++) { tmp[j] += str.charAt; } arrRslt = arrRslt.concat; } } } return arrRslt; } var strChineseFirstPY = "这段代码省略"; var oMultiDiff = { "40840": "YK", "40863": "QJG" }; var teststr; var selectobj = $; var obj; var obj1; var mfont = 12; var selectleft; var selecttop; var selectwidth; var objid; var objvalue; var objhtml; var inputwidth; var selectinput = 'selectinput', selectinputname = 'selectinputname', imgselect = 'imgselect', myhtml, objid; var recno; var fzrxm1 = ""; var fzrxm = ""; var selectid = -1; var mfocus = 1; var ij, selectgotoij = -10; //创建 select div selectobj.each { obj = $; var check = obj.attr; if { mfont = 12; selectleft = obj.offset().left; selecttop = obj.offset().top; selectwidth = obj.width(); objid = obj.attr; objvalue = obj.val(); objhtml = obj.find.text(); teststr = teststr + 'left=' + selectleft + 'and top=' + selecttop + '
'; //浏览器判断 if { inputwidth = selectwidth - 15; } else { inputwidth = selectwidth - 18; } selectsearch; // 隐藏 原始select selectobj.each { if == 'search') { $; //创建 select div function selectsearch() { myhtml = "

图片 1

"; if (!$('#' + selectinput + objid).html { obj.after; selectkeyup(); //添加keyup事件 } $('#' + selectinput + objid).css({ // 'left': selectleft, // 'top': selecttop, 'font-size': mfont, 'width': inputwidth }); $('#' + selectinputname + objid).css({ 'width': inputwidth }); $('#' + selectinputname + objid).val; $('#' + selectinputname + objid).focus { var myid; myid = $; objid = myid.replace("selectinputname", ""); obj = $('#' + selectinput + objid); }); /* $('#' + imgselect + objid).click { var myid; myid = $; objid = myid.replace; obj = $('#' + selectinput + objid); creatediv;*/ $('#' + selectinputname + objid).blur { var myid; myid = $; objid = myid.replace("selectinputname", ""); $('#' + selectinputname + objid).val.find.text; $('#' + imgselect + objid).attr("src", ""); //$.remove; //alert; $('#' + selectinput + objid).show(); //$('#' + selectinputname + objid).focus(); $('#' + selectinput + objid).hover { obj = $; }, function.attr; objid = objid.replace; $('#' + selectinputname + objid).val.find.text; $('#' + imgselect + objid).attr("src", ""); $.remove; } //创建 select 下拉 div 容器 function creatediv() { var divheight; objid = obj.attr; objid = objid.replace; $.attr("src", ""); // objid = $; $('#' + imgselect + objid).attr("src", "img/multiselect-hover.gif"); $('#' + selectinputname + objid).focus(); selectwidth = obj.width(); //浏览器判断 if { selectwidth = selectwidth + 16; } else { selectwidth = selectwidth + 20; } //divheight=$.l; //列表div var myhtml1 = "

"; $.remove(); obj.append; $.css({ 'font-size': mfont, 'width': selectwidth, }); $.show(); //加载option createoption { divheight = ij * 15; } else { divheight = 118; } $.css({ 'height': divheight, }); } function arraycheck { for (var i = 0; i < objs.length; i++) { if { return false; } } return true; } //创建 select option function createoption { objid = obj.attr; objid = objid.replace; //加载select option 数据 $.find.each { fzrxm1 = fzrxm1 + $ + "|"; fzrxm = fzrxm + $ + "|"; }); var mystr = '', selectgoto = $('#' + selectinputname + objid).val(), selectstyle = '', seachstr = ''; //alert; var myarray = new Array(); //创建一个数组 var arr = new Array(); //创建一个数组 fzrxm = fzrxm + ' '; arr = fzrxm.split; seachstr = $('#selectinputname' + objid).val; //seachstr = objvalstr; //$.html(seachstr + 'aaaaaaaaaaaaaa'); if && (seachstr != 'undefined')) { if { var rval = GetAllLikeString; } if { var rval = arr; } } else { var rval = arr; } mystr = "

"; ij = 0; recno = rval.length; //alert; if { for (var i = 0; i < recno; i++) { if (arraycheck { if && { ij = ij + 1; if (selectgoto == rval[i]) { selectgotoij = ij; selectstyle = "background: #0080FF;"; } mystr = mystr + "

" + rval[i] + "

"; selectstyle = ''; myarray.push; // 将一个或多个新元素添加到数组结尾,并返回数组新长度 } } } } else { mystr = mystr + "No records!"; } mystr = mystr + "

"; $.remove(); $.html; selectid = -1; myarray = ''; fzrxm1 = ''; fzrxm = ''; //alert; moveScrollbar; selectid = selectgotoij; selectgotoij = -10; optionhover(); } //获取所有符合条件下元素,以数据型式返回,str:要查找的字符串,container:被查的数组 function GetAllLikeString { var str = mstr; var startChar = str.charAt; //开始字符 var strLen = str.length; //查找符串的长度 var curCon; var isFind = false; //是否找到 var resultIndex = -1 //如果是的话的那个索引 var returnvalue = ""; for (var i = 0; i < container.length; i++) { curCon = container[i]; for (var j = 0; j < curCon.length; j++) { //alert; curstr = curCon.charAt; if (curstr == startChar || makePy //如果匹配起始字符,开始查找 { strsearch = curCon.substring.substring; strsearch1 = makePy; if (strsearch == str || strsearch1 == str) //如果从j开始的字符与str匹配,那ok { returnvalue = returnvalue + curCon

  • "|"; } } } } if (returnvalue.length > 1) returnvalue = returnvalue.substring(0, returnvalue.length - 1); var returnvalue = returnvalue.split; returnvalue.sort(); return returnvalue; } ////分类法选中样式操作/////////////////////////////////////////////////////// function optionhover() { objid = obj.attr; objid = objid.replace; var mform = $; mform.find.each { var _self = $; _self.click { // alert; setval; $; $.hide.attr("src", ""); }); _self.hover { if (getselectvalue != $ { mform.find.css({ background: "White" }); } $.css({ background: "#0080FF" }); }, function() { if (getselectvalue != $ { $.css({ background: "White" }); } }); }); } function getselectvalue { objid = obj.attr; objid = objid.replace; var myid = ''; $.find.each { if ) { myid = $; return false; //跳出循环 //alert; return myid; } function setval { objid = obj.attr; objid = objid.replace; //alert; if .length == 0) { return false; } $.attr('value', getselectvalue; $('#' + selectinputname + objid).val; }; function getTop { var mfontsize; return idx * 14 - 23; } //移动 option div 滚动条 function moveScrollbar { return false; } if { return false; } var t = getTop; var ch = $.scrollHeight; $.attr; // $.animate({scrollTop : t}, 'slow'); $.val($("#selectclassdiv" + idx).attr; setval($("#selectclassdiv" + idx).html; } function selectkeyup() { $('#' + selectinputname + objid).keyup { // alert; if { selectid = 0; // return false; }; if { selectid = 0; //return false; }; mfocus = 1; switch { case 37: { mfocus = 0; creatediv(); $("#selectclassdiv" + selectid).css({ background: "White" }); selectid = selectid - 1; moveScrollbar; $("#selectclassdiv"
  • selectid).css({ background: "#0080FF" }); break; } case 39: { mfocus = 0; creatediv(); $("#selectclassdiv" + selectid).css({ background: "White" }); selectid = selectid + 1; moveScrollbar; $("#selectclassdiv"
  • selectid).css({ background: "#0080FF" }); break; } case 40: { mfocus = 0; $("#selectclassdiv" + selectid).css({ background: "White" }); selectid = selectid + 1; moveScrollbar; $("#selectclassdiv" + selectid).css({ background: "#0080FF" }); break; } case 38: { mfocus = 0; creatediv(); $("#selectclassdiv" + selectid).css({ background: "White" }); selectid = selectid - 1; moveScrollbar; $("#selectclassdiv"
  • selectid).css({ background: "#0080FF" }); break; } case 13: { mfocus = 0; creatediv(); setval($("#selectclassdiv" + selectid).html.change(); $.hide.attr("src", ""); break; } case 9: { mfocus = 0; $.remove(); break; } } if { creatediv; }; }); $('#' + selectinputname + objid).click { $('#' + selectinputname + objid).select; } }; 使用方法: 复制代码 代码如下: 所有学校 湾小学 阳河小学 浏阳市 JS代码: 复制代码 代码如下:$.ready{ $.selectseach; 下载地址: //www.jb51.net/jiaoben/27673.html一直想找一个可以通过拼音来查找下拉框optIOn值的插件,,这款插件一步到位全做到了,而且还支持可编辑的输入框

版权声明:本文由本港台现场报码发布于网站首页,转载请注明出处:通过jQuery打造支持汉字