<scripttype="text/javascript">
varkey2code={65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",
75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",
85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",49:"1",50:"2",51:"3",52:"4",
53:"5",54:"6",55:"7",56:"8",57:"9",48:"0"
};
</script>
<scriptlanguage=javascript>
varspell={0xB0A1:"a",0xB0A3:"ai",0xB0B0:"an",0xB0B9:"ang",0xB0BC:"ao",0xB0C5:"ba",0xB0D7:"bai",0xB0DF:"ban",0xB0EE:"bang",0xB0FA:"bao",0xB1AD:"bei",0xB1BC:"ben",0xB1C0:"beng",0xB1C6:"bi",0xB1DE:"bian",0xB1EA:"biao",0xB1EE:"bie",0xB1F2:"bin",0xB1F8:"bing",0xB2A3:"bo",0xB2B8:"bu",0xB2C1:"ca",0xB2C2:"cai",0xB2CD:"can",0xB2D4:"cang",0xB2D9:"cao",0xB2DE:"ce",0xB2E3:"ceng",0xB2E5:"cha",0xB2F0:"chai",0xB2F3:"chan",0xB2FD:"chang",0xB3AC:"chao",0xB3B5:"che",0xB3BB:"chen",0xB3C5:"cheng",0xB3D4:"chi",0xB3E4:"chong",0xB3E9:"chou",0xB3F5:"chu",0xB4A7:"chuai",0xB4A8:"chuan",0xB4AF:"chuang",0xB4B5:"chui",0xB4BA:"chun",0xB4C1:"chuo",0xB4C3:"ci",0xB4CF:"cong",0xB4D5:"cou",0xB4D6:"cu",0xB4DA:"cuan",0xB4DD:"cui",0xB4E5:"cun",0xB4E8:"cuo",0xB4EE:"da",0xB4F4:"dai",0xB5A2:"dan",0xB5B1:"dang",0xB5B6:"dao",0xB5C2:"de",0xB5C5:"deng",0xB5CC:"di",0xB5DF:"dian",0xB5EF:"diao",0xB5F8:"die",0xB6A1:"ding",0xB6AA:"diu",0xB6AB:"dong",0xB6B5:"dou",0xB6BC:"du",0xB6CB:"duan",0xB6D1:"dui",0xB6D5:"dun",0xB6DE:"duo",0xB6EA:"e",0xB6F7:"en",0xB6F8:"er",0xB7A2:"fa",0xB7AA:"fan",0xB7BB:"fang",0xB7C6:"fei",0xB7D2:"fen",0xB7E1:"feng",0xB7F0:"fo",0xB7F1:"fou",0xB7F2:"fu",0xB8C1:"ga",0xB8C3:"gai",0xB8C9:"gan",0xB8D4:"gang",0xB8DD:"gao",0xB8E7:"ge",0xB8F8:"gei",0xB8F9:"gen",0xB8FB:"geng",0xB9A4:"gong",0xB9B3:"gou",0xB9BC:"gu",0xB9CE:"gua",0xB9D4:"guai",0xB9D7:"guan",0xB9E2:"guang",0xB9E5:"gui",0xB9F5:"gun",0xB9F8:"guo",0xB9FE:"ha",0xBAA1:"hai",0xBAA8:"han",0xBABB:"hang",0xBABE:"hao",0xBAC7:"he",0xBAD9:"hei",0xBADB:"hen",0xBADF:"heng",0xBAE4:"hong",0xBAED:"hou",0xBAF4:"hu",0xBBA8:"hua",0xBBB1:"huai",0xBBB6:"huan",0xBBC4:"huang",0xBBD2:"hui",0xBBE7:"hun",0xBBED:"huo",0xBBF7:"ji",0xBCCE:"jia",0xBCDF:"jian",0xBDA9:"jiang",0xBDB6:"jiao",0xBDD2:"jie",0xBDED:"jin",0xBEA3:"jing",0xBEBC:"jiong",0xBEBE:"jiu",0xBECF:"ju",0xBEE8:"juan",0xBEEF:"jue",0xBEF9:"jun",0xBFA6:"ka",0xBFAA:"kai",0xBFAF:"kan",0xBFB5:"kang",0xBFBC:"kao",0xBFC0:"ke",0xBFCF:"ken",0xBFD3:"keng",0xBFD5:"kong",0xBFD9:"kou",0xBFDD:"ku",0xBFE4:"kua",0xBFE9:"kuai",0xBFED:"kuan",0xBFEF:"kuang",0xBFF7:"kui",0xC0A4:"kun",0xC0A8:"kuo",0xC0AC:"la",0xC0B3:"lai",0xC0B6:"lan",0xC0C5:"lang",0xC0CC:"lao",0xC0D5:"le",0xC0D7:"lei",0xC0E2:"leng",0xC0E5:"li",0xC1A9:"lia",0xC1AA:"lian",0xC1B8:"liang",0xC1C3:"liao",0xC1D0:"lie",0xC1D5:"lin",0xC1E1:"ling",0xC1EF:"liu",0xC1FA:"long",0xC2A5:"lou",0xC2AB:"lu",0xC2BF:"lv",0xC2CD:"luan",0xC2D3:"lue",0xC2D5:"lun",0xC2DC:"luo",0xC2E8:"ma",0xC2F1:"mai",0xC2F7:"man",0xC3A2:"mang",0xC3A8:"mao",0xC3B4:"me",0xC3B5:"mei",0xC3C5:"men",0xC3C8:"meng",0xC3D0:"mi",0xC3DE:"mian",0xC3E7:"miao",0xC3EF:"mie",0xC3F1:"min",0xC3F7:"ming",0xC3FD:"miu",0xC3FE:"mo",0xC4B1:"mou",0xC4B4:"mu",0xC4C3:"na",0xC4CA:"nai",0xC4CF:"nan",0xC4D2:"nang",0xC4D3:"nao",0xC4D8:"ne",0xC4D9:"nei",0xC4DB:"nen",0xC4DC:"neng",0xC4DD:"ni",0xC4E8:"nian",0xC4EF:"niang",0xC4F1:"niao",0xC4F3:"nie",0xC4FA:"nin",0xC4FB:"ning",0xC5A3:"niu",0xC5A7:"nong",0xC5AB:"nu",0xC5AE:"nv",0xC5AF:"nuan",0xC5B0:"nue",0xC5B2:"nuo",0xC5B6:"o",0xC5B7:"ou",0xC5BE:"pa",0xC5C4:"pai",0xC5CA:"pan",0xC5D2:"pang",0xC5D7:"pao",0xC5DE:"pei",0xC5E7:"pen",0xC5E9:"peng",0xC5F7:"pi",0xC6AA:"pian",0xC6AE:"piao",0xC6B2:"pie",0xC6B4:"pin",0xC6B9:"ping",0xC6C2:"po",0xC6CB:"pu",0xC6DA:"qi",0xC6FE:"qia",0xC7A3:"qian",0xC7B9:"qiang",0xC7C1:"qiao",0xC7D0:"qie",0xC7D5:"qin",0xC7E0:"qing",0xC7ED:"qiong",0xC7EF:"qiu",0xC7F7:"qu",0xC8A6:"quan",0xC8B1:"que",0xC8B9:"qun",0xC8BB:"ran",0xC8BF:"rang",0xC8C4:"rao",0xC8C7:"re",0xC8C9:"ren",0xC8D3:"reng",0xC8D5:"ri",0xC8D6:"rong",0xC8E0:"rou",0xC8E3:"ru",0xC8ED:"ruan",0xC8EF:"rui",0xC8F2:"run",0xC8F4:"ruo",0xC8F6:"sa",0xC8F9:"sai",0xC8FD:"san",0xC9A3:"sang",0xC9A6:"sao",0xC9AA:"se",0xC9AD:"sen",0xC9AE:"seng",0xC9AF:"sha",0xC9B8:"shai",0xC9BA:"shan",0xC9CA:"shang",0xC9D2:"shao",0xC9DD:"she",0xC9E9:"shen",0xC9F9:"sheng",0xCAA6:"shi",0xCAD5:"shou",0xCADF:"shu",0xCBA2:"shua",0xCBA4:"shuai",0xCBA8:"shuan",0xCBAA:"shuang",0xCBAD:"shui",0xCBB1:"shun",0xCBB5:"shuo",0xCBB9:"si",0xCBC9:"song",0xCBD1:"sou",0xCBD4:"su",0xCBE1:"suan",0xCBE4:"sui",0xCBEF:"sun",0xCBF2:"suo",0xCBFA:"ta",0xCCA5:"tai",0xCCAE:"tan",0xCCC0:"tang",0xCCCD:"tao",0xCCD8:"te",0xCCD9:"teng",0xCCDD:"ti",0xCCEC:"tian",0xCCF4:"tiao",0xCCF9:"tie",0xCCFC:"ting",0xCDA8:"tong",0xCDB5:"tou",0xCDB9:"tu",0xCDC4:"tuan",0xCDC6:"tui",0xCDCC:"tun",0xCDCF:"tuo",0xCDDA:"wa",0xCDE1:"wai",0xCDE3:"wan",0xCDF4:"wang",0xCDFE:"wei",0xCEC1:"wen",0xCECB:"weng",0xCECE:"wo",0xCED7:"wu",0xCEF4:"xi",0xCFB9:"xia",0xCFC6:"xian",0xCFE0:"xiang",0xCFF4:"xiao",0xD0A8:"xie",0xD0BD:"xin",0xD0C7:"xing",0xD0D6:"xiong",0xD0DD:"xiu",0xD0E6:"xu",0xD0F9:"xuan",0xD1A5:"xue",0xD1AB:"xun",0xD1B9:"ya",0xD1C9:"yan",0xD1EA:"yang",0xD1FB:"yao",0xD2AC:"ye",0xD2BB:"yi",0xD2F0:"yin",0xD3A2:"ying",0xD3B4:"yo",0xD3B5:"yong",0xD3C4:"you",0xD3D9:"yu",0xD4A7:"yuan",0xD4BB:"yue",0xD4C5:"yun",0xD4D1:"za",0xD4D4:"zai",0xD4DB:"zan",0xD4DF:"zang",0xD4E2:"zao",0xD4F0:"ze",0xD4F4:"zei",0xD4F5:"zen",0xD4F6:"zeng",0xD4FA:"zha",0xD5AA:"zhai",0xD5B0:"zhan",0xD5C1:"zhang",0xD5D0:"zhao",0xD5DA:"zhe",0xD5E4:"zhen",0xD5F4:"zheng",0xD6A5:"zhi",0xD6D0:"zhong",0xD6DB:"zhou",0xD6E9:"zhu",0xD7A5:"zhua",0xD7A7:"zhuai",0xD7A8:"zhuan",0xD7AE:"zhuang",0xD7B5:"zhui",0xD7BB:"zhun",0xD7BD:"zhuo",0xD7C8:"zi",0xD7D7:"zong",0xD7DE:"zou",0xD7E2:"zu",0xD7EA:"zuan",0xD7EC:"zui",0xD7F0:"zun",0xD7F2:"zuo"}
varspellArray=newArray()
varpn=""
/*for(vari=0xB0A1;i<0xD7FC;i++)
{
if(spell[i])pn=spell[i]
execScript("char=chr(\""+i+"\")","vbscript")
spellArray[char.charCodeAt(0)]=pn
}*/
functionpinyin(char)
{
if(!char.charCodeAt(0)||char.charCodeAt(0)<1328)returnchar;
if(spellArray[char.charCodeAt(0)])returnspellArray[char.charCodeAt(0)]
execScript("ascCode=hex(asc(\""+char+"\"))","vbscript")
ascCode=eval("0x"+ascCode)
if(!(ascCode>0xB0A0&&ascCode<0xD7FC))returnchar;
for(vari=ascCode;(!spell[i]&&i>0);)i--
returnspell[i]
}
functiontoPinyin(str)
{
varpStr=""
for(vari=0;i<str.length;i++)
{
if(str.charAt(i)=="\n")pStr+="<br>"
elsepStr+="<rubystyle='ruby-align:center'>"+str.charAt(i)+"<rt>"+pinyin(str.charAt(i))+"</rt></ruby>"
//elsepStr+=pinyin(str.charAt(i))+""
}
returnpStr
}
functiontoPinyinOnly(str)
{
varpStr=""
for(vari=0;i<str.length;i++)
{
if(str.charAt(i)=="\n")pStr+="<br>"
elsepStr+=""+pinyin(str.charAt(i));
//elsepStr+=pinyin(str.charAt(i))+""
}
returnpStr
}
functiontoPinyinShengmu(str)
{
varpStr=""
for(vari=0;i<str.length;i++)
{
if(str.charAt(i)=="\n")pStr+="";
elsepStr+=pinyin(str.charAt(i)).charAt(0);
//elsepStr+=pinyin(str.charAt(i))+""
}
returnpStr
}
functionpinyinSort(a,b)
{
varrValue=0
for(vari=0;i<a.length;i++)
{
varpinA=pinyin(a.charAt(i))
varpinB=pinyin(b.charAt(i))
if(rValue=pinA>pinB?1:pinA<pinB?-1:0)break
}
returnrValue
}
</script>
<textareaid=kevincols=100rows=10>小狗收藏贴</textarea><br>
<buttononclick="test.innerHTML=toPinyin(kevin.innerText)">转换</button>
<buttononclick="test.innerHTML=toPinyinShengmu(kevin.innerText)">转换sm</button>
<buttononclick="test.innerHTML=toPinyinOnly(kevin.innerText)">仅拼音</button>
<buttononclick="test.innerHTML=kevin.innerText.split('').sort(pinyinSort).join('')">排序</button>
<divid=teststyle="font-size:16px;"></div>
select选择,支持中文
#先选择select,按下键盘字母,option根据所输入字母自动选择匹配的中文,如果要重新选择,按space键盘
改变option顺序
<selectid="sel"onkeydown="showOptions2(this)"onfocus="inp='';">
<optionvalue=1>中国</option>
<optionvalue=1>北京</option>
<optionvalue=1>北京1北京</option>
<optionvalue=1>北京1南京</option>
<optionvalue=1>北京2</option>
<optionvalue=1>北京3</option>
<optionvalue=1>上海</option>
<optionvalue=1>天津</option>
<optionvalue=1>天津人口</option>
<optionvalue=1>人口</option>
<optionvalue=1>人们</option>
<optionvalue=1>人民</option>
</select>
不改变option顺序
<selectid="sel"onkeydown="showOptions(this)"onfocus="inp='';">
<optionvalue=1>中国</option>
<optionvalue=1>北京</option>
<optionvalue=1>北京1北京</option>
<optionvalue=1>北京1南京</option>
<optionvalue=1>北京2</option>
<optionvalue=1>北京3</option>
<optionvalue=1>上海</option>
<optionvalue=1>天津</option>
<optionvalue=1>天津人口</option>
<optionvalue=1>人口</option>
<optionvalue=1>人们</option>
<optionvalue=1>人民</option>
</select>
<scripttype='text/javascript'>
varinp="";
functionshowOptions(obj){
if(event.keyCode==32){
inp="";
return;
}
vartmp=inp;
tmp+=key2code[event.keyCode]?key2code[event.keyCode]:"";
varsomeNodeList=obj.getElementsByTagName('option');
varindex=-1;
for(vari=0;i<someNodeList.length;i++){
varsm=toPinyinShengmu(someNodeList[i].innerHTML);
if(sm.indexOf(tmp)==0){
index=i;
break;
}
}
if(index>=0){
obj.selectedIndex=index;
inp=tmp;
}
}
functionshowOptions2(obj){
if(event.keyCode==32){
inp="";
return;
}
vartmp=inp;
tmp+=key2code[event.keyCode]?key2code[event.keyCode]:"";
varsomeNodeList=obj.getElementsByTagName('option');
varindex=-1;
varchoose=[];
for(vari=someNodeList.length-1;i>0;i--){
varsm=toPinyinShengmu(someNodeList[i].innerHTML);
if(sm.indexOf(tmp)==0){
inp=tmp;
choose[choose.length]=someNodeList[i];
obj.removeChild(someNodeList[i]);
}
}
if(choose.length>0){
someNodeList=obj.getElementsByTagName('option');
varlen=someNodeList.length;
for(vari=0;i<len;i++){
choose[choose.length]=someNodeList[i];
}
for(vari=0;i<choose.length;i++){
obj.appendChild(choose[i]);
}
obj.selectedIndex=0;
}
someNodeList=null;
choose=null;
}
</script>
分享到:
相关推荐
### JS 获取中文拼音与 Select 自动匹配字母获取值的实现 在前端开发中,有时我们需要将汉字转换为拼音,或者根据拼音的首字母来进行数据筛选等操作。这在实现一些特殊功能时非常有用,比如根据拼音首字母进行快速...
这里涉及到汉字转拼音的技术,可以使用JavaScript库如pinyin.js或hanyu-pinyin来处理。在预处理阶段,我们需要遍历所有选项,获取每个选项文本的拼音,并将其存储到相应的选项对象中。 接下来,我们需要覆盖Select2...
为了处理中文首字母搜索,`pinyin.js` 可能提供了获取汉字首字母的功能。 在实际应用中,可能还需要考虑到性能优化,比如在用户输入时使用debounce或throttle函数限制搜索请求的频率,以及使用缓存策略来避免重复...
在“bootstrap select 下拉框通过拼音搜索汉字”这个实例中,我们关注的重点是如何利用该插件实现通过输入拼音来搜索并筛选汉字的功能,这对于中文环境下的用户体验提升有着显著的作用。 首先,我们要了解Bootstrap...
这意味着用户在输入框中输入拼音或者拼音首字母时,下拉选项能根据输入自动筛选出匹配的结果,提高了用户查找和选择的速度。 实现这一功能的关键在于配置select2的搜索函数。通过监听输入事件,对用户输入的拼音...
这个功能的核心在于,当用户在搜索框中输入拼音或首字母时,`Select2` 需要能识别并匹配相应的中文选项。这里可以利用 JavaScript 的字符串处理函数,对每个选项的中文文本进行拼音转换,然后进行比较。 1. **拼音...
这通常涉及到自定义搜索函数,让 Select2 在处理用户输入时不仅匹配汉字,还要匹配拼音。 ```javascript $("#select-element").select2({ // 其他配置项... minimumInputLength: 1, matcher: function (params, ...
在这个“Layui首字母搜索下拉框”的主题中,我们将深入探讨如何利用Layui实现一个高效的首字母、拼音或中文搜索功能,以提升用户在大量数据中的查找体验。 首先,我们需要了解Layui的基础结构。Layui的核心在于它的...
在JavaScript(JS)编程中,将汉字转换成拼音首字母代码是一种常见的需求,尤其是在实现诸如自动补全、拼音检索等功能时。这篇文档将详细介绍如何利用JS实现这一功能,并结合输入框、下拉列表等交互元素,创建一个...
简拼指的是用每个汉字拼音的第一个字母来代表整个单词,例如“北京”可以表示为“bj”。全拼则是输入完整的汉字拼音,如“bei jing”。这种功能的实现通常需要在后端或者前端进行数据处理,将每个选项的拼音与用户...
在JavaScript编程领域,汉字拼音首字母自动获取是一个常见的需求,特别是在中文输入法或者搜索功能的实现上。这个特效代码提供了一种解决方案,使得用户在文本框输入汉字时,能够自动匹配并显示对应的拼音首字母,...
以chosen.jQuery.js与pinyin.js两个文件合并成可根据拼音搜索中文的下拉功能目前支持每个中文的首字母查询,如果需要全拼音查询,只需修改chosen.jquery.js 344行左右处,把search_string_m = ping[0];改成search_...
例如,我们可以创建一个`<input>`标签作为搜索框,用户可以在这里输入城市拼音的首字母,以及一个`<select>`标签作为下拉列表,显示匹配的城市选项。 ```html <!DOCTYPE html> 按字母选择城市 请输入城市...
汉字首拼查询是指用户输入汉字的首字母拼音,系统通过匹配选项中的拼音首字母进行筛选。例如,如果用户输入“sh”,系统会显示所有以“sh”开头的汉字相关的选项,如“上海”、“深圳”等。这种方式简洁高效,特别...
首先,我们需要一个函数来获取汉字的拼音首字母。在这个例子中,使用了VBScript的`asc()`函数来获取字符的ASCII码,然后通过一系列的条件判断来确定对应的拼音首字母。例如,如果ASCII码在45217到45252之间,那么...
3. **处理键盘输入**: 在`handleKeyUp`函数中,获取输入框的值,然后根据拼音映射表查找匹配的选项。 4. **过滤并显示匹配项**: 根据输入的拼音或拼音首字母,过滤出匹配的`<option>`元素,然后动态更新下拉列表的...
"改写下jquery.searchableSelect.js 支持汉字模糊查询"这个主题,就是关于如何优化一个JavaScript插件,使其能更好地适应中文环境,提升用户在下拉框中搜索汉字的效率。 `jquery.searchableSelect.js`是一个jQuery...
// 这里可以使用第三方库如pinyin.js来处理汉字到拼音的转换 // 为了简化,这里假设每个选项的文本都是单个汉字 var pinyin = getPinyin(text.charAt(0)); // 假设getPinyin函数能获取汉字首字母 return pinyin....