Js-based Chinese Character sorting method, js-based Chinese Character sorting
This example describes how to sort Chinese Characters in JavaScript. Share it with you for your reference. The details are as follows:
<Script type = "text/javascript"> <! -- Function startSort () {var a = document. getElementById ('s '). value; a =. split (','). sort (); document. getElementById ('r1 '). value = a;. sort (function (a, B) {return. localeCompare (B)}); document. getElementById ('r2 '). value = a ;}// --> </script> <p> string array containing Chinese characters (separated by commas ): <br/> <textarea id = "s" style = "width: 100%; overflow: scroll; word-wrap: normal;" rows = "10"> Zhang Shaohan, B tu, abort, Zhang Xueyou, something, apple, February 22, May, Andy Lau, banana, apple, Fan Xiaoqi, asan </textarea> </p> <p style = "text-align: center "> <input type =" button "value =" Sort Test "onclick =" startSort () "style =" width: 300px "/> </p> <p> default sorting result: <br/> <textarea id =" r1 "style =" width: 100%; overflow: scroll; word-wrap: normal; "rows =" 10 "> </textarea> </p> <p> Chinese pinyin sorting result: <br/> <textarea id = "r2" style = "width: 100%; overflow: scroll; word-wrap: normal; "rows =" 10 "> </textarea> </p>
I hope this article will help you design javascript programs.