读书人

怎么用JS繁中文字排序

发布时间: 2012-02-21 16:26:23 作者: rapoo

如何用JS繁中文字排序!
如何下面代工、姓名、部、按照相按行排序(繁中文按拼音排序)?

按 <input style= "cursor:hand; " class= "button2 " type= "button " value= "工 " name= "btnTest " Title= " "> <input style= "cursor:hand; " class= "button2 " type= "button " value= "姓名 " name= "B3 " Title= " " OnClick= "SelGen( 'Cmd0 ') "> <input style= "cursor:hand; " class= "button2 " type= "button " value= "部 " name= "B3 " Title= " " OnClick= "SelGen( 'Cmd0 ') "> <input style= "cursor:hand; " class= "button2 " type= "button " value= " " name= "B3 " Title= " " OnClick= "SelGen( 'Cmd0 ') "> 排序
<select name= "GenSel " size= "10 " ondblclick= "SelGen( 'Cmd0 ') " style= "font-family: 明; font-size: 9pt; height: 450; width:100% " multiple>

<option value= "000195|高 "> 000195|高|品保部|工 </option>
<option value= "000387|魏秀 "> 000387|魏秀|品保部|工 </option>
<option value= "002341|花藏 "> 002341|花藏|品保部|工 </option>
<option value= "003232|光娥 "> 003232|光娥|品保部|工 </option>
<option value= "002575|玉 "> 002575|玉|品保部|工 </option>
<option value= "000215|李珍 "> 000215|李珍|品保部|工 </option>
<option value= "000047|付喜 "> 000047|付喜|品保部| </option>
<option value= "000276|任小蓉 "> 000276|任小蓉|品保部|工 </option>
<option value= "000384|辜建英 "> 000384|辜建英|品保部|工 </option>
<option value= "000215|李珍 "> 000215|李珍|品保部|工 </option>
<option value= "000047|付喜 "> 000047|付喜|品保部| </option>
<option value= "000276|任小蓉 "> 000276|任小蓉|品保部|工 </option>
<option value= "000384|辜建英 "> 000384|辜建英|品保部|工 </option>

</select>

[解决办法]
按 <input style= "cursor:hand; " class= "button2 " type= "button " value= "工 " name= "btnTest " Title= " " OnClick= "SelGen(0) "> <input style= "cursor:hand; " class= "button2 " type= "button " value= "姓名 " name= "B3 " Title= " " OnClick= "SelGen(1) "> <input style= "cursor:hand; " class= "button2 " type= "button " value= "部 " name= "B3 " Title= " " OnClick= "SelGen(2) "> <input style= "cursor:hand; " class= "button2 " type= "button " value= " " name= "B3 " Title= " " OnClick= "SelGen(3) "> 排序


<select id= "GenSel " size= "10 " style= "font-family: 明; font-size: 9pt; height: 450; width:100% " multiple>
<option value= "000387|魏秀|品保部|主管 "> 000387|魏秀|品保部|主管 </option>
<option value= "000195|高|品保部|工 "> 000195|高|品保部|工 </option>
<option value= "002341|花藏|市部|工 "> 002341|花藏|市部|工 </option>
<option value= "003232|光娥|售部|理 "> 003232|光娥|售部|理 </option>
</select>
<script language= "javascript ">
Array.prototype.cnsort = function(){//此做排序理
return this.sort();
}

function SelGen(index){
var select = document.getElementById( "GenSel ");
var tempArray = new Array();
var keyArray = new Array();
var length = select.options.length;
for(i=0;i <length;i++){
var item = select.options[0].value;
var arrKey = item.split( "| ");
var key = arrKey[index];
keyArray[i] = key+i;
tempArray[key.toString()+i] = item;
select.options.remove(0);
}
keyArray = keyArray.cnsort();
for(i=0;i <keyArray.length;i++){
var value = tempArray[keyArray[i]];
select.options.add(new Option(value,value));
}
}
</script>

读书人网 >JavaScript

热点推荐