<div class="codetitle"> <span><a style="CURSOR: pointer" data="86243" class="copybut" id="copybut86243" onclick="doCopy('code86243')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code86243"> <br><title>JavaScript對文字依照拼音排序</title> <br><br><title>JavaScript對文字依照拼音排序</title> <br><script type="text/javascript"><BR>function defaultSort(){<BR>var a="zhongguo,daguo,世界,中國,超級大國";<BR>a=a.split("," );<BR>a.sort();<BR>alert(a);<BR>}<BR>function cusSort(){<BR>var a="zhongguo,daguo,世界,中國,超級大國"; <BR>a=a.split(",");<BR>a.sort(function(a,b){<BR> return a.localeCompare(b);<BR>});<BR>alert( a);<BR>}<BR></script><br><a href="#" onclick="defaultSort();">預設排序</a><br> </div> <a href="#" onclick="cusSort();">依拼音字母排序</a>