JavaScript text in accordance with the pinyin sorting implementation code

  • 2020-03-30 01:05:39
  • OfStack


<title>JavaScript Sort words by pinyin </title>
<SCRIPT type="text/javascript">
function defaultSort(){
var a="zhongguo,daguo, The world , China , The superpower ";
a=a.split(",");
a.sort();
alert(a);
}
function cusSort(){
var a="zhongguo,daguo, The world , China , The superpower ";
a=a.split(",");
a.sort(function(a,b){
  return a.localeCompare(b);
});
alert(a);
}
</SCRIPT>
<a href="#" onClick="defaultSort();"> The default sort </a><br>
<a href="#" onClick="cusSort();"> In alphabetical order </a>        

Related articles: