欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實現(xiàn)漢字排序的方法

 更新時間:2015年07月23日 17:16:17   作者:fzhlee  
這篇文章主要介紹了js實現(xiàn)漢字排序的方法,涉及javascript針對中文編碼的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了js實現(xiàn)漢字排序的方法。分享給大家供大家參考。具體如下:

<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>
<p>包含漢字的字符串?dāng)?shù)組(用逗號","隔開):<br />
<textarea id="s" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10">張韶涵,b土,abort,張學(xué)友,something,蘋果,五月天,劉德華,香蕉,apple,范瑋琪,阿桑</textarea></p>
<p style="text-align: center"><input type="button" value="排序測試" onclick="startSort()" style="width: 300px" /></p>
<p>默認(rèn)排序結(jié)果:<br />
<textarea id="r1" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10"></textarea></p>
<p>漢字拼音順序排序結(jié)果:<br />
<textarea id="r2" style="width: 100%; overflow: scroll; word-wrap: normal;" rows="10"></textarea></p>

希望本文所述對大家的javascript程序設(shè)計有所幫助。

相關(guān)文章

最新評論