JavaScript字母、汉字混合的拼音排序列表框
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Select列表汉字拼音排序</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
function sortRule(a,b) {
var x = a._text;
var y = b._text;
return x.localeCompare(y);
}
function op(){
var _value;
var _text;
}
function sortOption(){
var obj = document.getElementById("city");
var tmp = new Array();
for(var i=0;i<obj.options.length;i++){
var ops = new op();
ops._value = obj.options[i].value;
ops._text = obj.options[i].text;
tmp.push(ops);
}
tmp.sort(sortRule);
for(var j=0;j<tmp.length;j++){
obj.options[j].value = tmp[j]._value;
obj.options[j].text = tmp[j]._text;
}
}
sortOption();
</SCRIPT>
<Select NAME="citys" id="city">
<option value="1">上海</>
<option value="2">北京</>
<option value="3">济南</>
<option value="4">拉萨</>
<option value="5">深圳</>
<option value="6">重庆</>
<option value="7">天津</>
<option value="8">南京</>
<option value="9">无锡</>
<option value="10">苏州</>
<option value="11">石家庄</>
<option value="12">成都</>
<option value="13">长沙</>
<option value="14">海口</>
<option value="15">翟某</>
<option value="16">台北</>
</Select>
</BODY>
</HTML>