JS-中文排序

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
   <script type="text/javascript"> 
  function startSort(){
  var a=document.getElementById('s').value; 
  a=a.split(',') ;
  a.sort(); 
  document.getElementById('r1').value=a;
  a.sort(function(a,b){  return a.localeCompare(b)}  ); 
  document.getElementById('r2').value=a; 
  } 
  
 
  </script>
 </HEAD>

 <BODY>
 
  <p>包含汉字的字符串数组(用逗号","隔开):
  <br /> 
  <textarea id="s" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10">张韶涵,a,zbort,刘学友,杨omething,苹果,五月天,刘德华,香蕉,杨apple,范玮琪,阿桑</textarea>
  </p> 
  <p style="text-align: center">
  <input type="button" value="排序测试" onclick="startSort()" style="width: 300px" /></p> 
  <p>默认排序结果:<br /> <textarea id="r1" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10"></textarea></p>
  <p>汉字拼音顺序排序结果:<br /> <textarea id="r2" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10"></textarea></p> 
 </BODY>
</HTML>

 

你可能感兴趣的:(JavaScript,html,apple)