Google has been a lot of time to find out on the foreign site on how to compare chinese, the original address: http://www.webdeveloper.com/forum/showthread.php?t=9365
Premise: Use Unicode encoding, If other GBK this method should not!
Definition and usage
Compares two strings in a local-specific order.
Stringobject.localecompare (target)
Target: a string to compare with Stringobject in a local-specific order
Test 1:
var str= "beijing"; var var2= "beijing"; var res=str.localecompare (var2); Console.log (res); Output 0
Test 2
var str= "Monday"; var var2= "Tuesday"; var res=str.localecompare (var2); Console.log (res); Output 1
Test 3
var str= "Wednesday"; var var2= "Monday"; var res=str.localecompare (var2); alert (res); Output-1
Test 4
To implement phonetic sorting in chinese:
<! DOCTYPE html>
Localecompare () method to achieve phonetic sorting in Chinese