文章主要介紹了javascript實現漢字轉拼音代碼分享,非常的實用,從項目中分離出來的,這裡分享給大家,有需要的小伙伴可以參考下。
js代碼
?
1 2 3 4 5 6 7 8 function arraySearch(l1,l2){ for (var name in PinYin){ if (PinYin[name].indexOf(l1)!=-1) { return name; break; } } return false; }核心代碼:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 var PinYin = {"a":"u554au963fu9515","ai":"u57c3u6328u54ceu5509u54c0u7691u764cu853cu77eeu827eu788du7231u9698u8bf6u6371u55f3u55ccu5ad2u7477u66a7u7839u953fu972d","an":"u978du6c28u5b89u4ffau6309u6697u5cb8u80fau6848u8c19u57efu63deu72b4u5eb5u6849u94f5u9e4cu9878u9eef","ang":"u80aeu6602u76ce","ao":"u51f9u6556u71acu7ff1u8884u50b2u5965u61cau6fb3u5773u62d7u55f7u5662u5c99u5ed2u9068u5aaau9a9cu8071u87afu93cau9cccu93d6","ba":"u82adu634cu6252u53edu5427u7b06u516bu75a4u5df4u62d4u8dcbu9776u628au8019u575du9738u7f62u7238u8307u83ddu8406u636du5c9cu705eu6777u94afu7c91u9c85u9b43","bai":"u767du67cfu767eu6446u4f70u8d25u62dcu7a17u859cu63b0u97b4","ban":"u6591u73edu642cu6273u822cu9881u677fu7248u626eu62ccu4f34u74e3u534au529eu7ecau962au5742u8c73u94a3u7622u764du8228","bang":"u90a6u5e2eu6886u699cu8180u7ed1u68d2u78c5u868cu9551u508du8c24u84a1u8783","bao":"u82deu80deu5305u8912u96f9u4fddu5821u9971u5b9du62b1u62a5u66b4u8c79u9c8du7206u52f9u8446u5b80u5b62u7172u9e28u8913u8db5u9f85","bo":"u5265u8584u73bbu83e0u64adu62e8u94b5u6ce2u535au52c3u640fu94c2u7b94u4f2fu5e1bu8236u8116u818au6e24u6ccau9a73u4eb3u8543u5575u997du6a97u64d8u7934u94b9u9e41u7c38u8ddb","bei":"u676fu7891u60b2u5351u5317u8f88u80ccu8d1du94a1u500du72c8u5907u60ebu7119u88abu5b5bu9642u90b6u57e4u84d3u5457u602bu6096u789au9e4eu8919u943e","ben":"u5954u82efu672cu7b28u755au574cu951b","beng":"u5d29u7ef7u752du6cf5u8e66u8ff8u552au5623u750f","bi":"u903cu9f3bu6bd4u9119u7b14u5f7cu78a7u84d6u853du6bd5u6bd9u6bd6u5e01u5e87u75f9u95edu655du5f0au5fc5u8f9fu58c1u81c2u907fu965bu5315u4ef3u4ffeu8298u835cu8378u5421u54d4u72f4u5eb3u610eu6ed7u6fdeu5f3cu59a3u5a62u5b16u74a7u8d32u7540u94cbu79d5u88e8u7b5au7b85u7be6u822du895eu8df8u9ac0","bian":"u97adu8fb9u7f16u8d2cu6241u4fbfu53d8u535eu8fa8u8fa9u8fabu904du533eu5f01u82c4u5fedu6c74u7f0fu7178u782du78a5u7a39u7a86u8759u7b3eu9cca","biao":"u6807u5f6au8198u8868u5a4au9aa0u98d1u98d9u98dau706cu9556u9573u762du88f1u9cd4","bie":"u9cd6u618bu522bu762au8e69u9cd8","bin":"u5f6cu658cu6fd2u6ee8u5bbeu6448u50a7u6d5cu7f24u73a2u6ba1u8191u9554u9accu9b13","bing":"u5175u51b0u67c4u4e19u79c9u997cu70b3u75c5u5e76u7980u90b4u6452u7ee0u678bu69dfu71f9","bu":"u6355u535cu54fau8865u57e0u4e0du5e03u6b65u7c3fu90e8u6016u62cau535fu900bu74ffu6661u949au91ad","ca":"u64e6u5693u7924","cai":"u731cu88c1u6750u624du8d22u776cu8e29u91c7u5f69u83dcu8521","can":"u9910u53c2u8695u6b8bu60edu60e8u707fu9a96u74a8u7cb2u9eea","cang":"u82cdu8231u4ed3u6ca7u85cfu4f27","cao":"u64cdu7cd9u69fdu66f9u8349u8279u5608u6f15u87acu825a","ce":"u5395u7b56u4fa7u518cu6d4bu5202u5e3bu607b","ceng":"u5c42u8e6du564c","cha":"u63d2u53c9u832cu8336u67e5u78b4u643du5bdfu5c94u5deeu8be7u7339u9987u6c4au59f9u6748u6942u69ceu6aabu9497u9538u9572u8869","chai":"u62c6u67f4u8c7au4faau8308u7625u867fu9f87","chan":"u6400u63bau8749u998bu8c17u7f20u94f2u4ea7u9610u98a4u5181u8c04u8c36u8487u5edbu5fcfu6f7au6fb6u5b71u7fbcu5a75u5b17u9aa3u89c7u7985u9561u88e3u87feu8e94","chang":"u660cu7316u573au5c1du5e38u957fu507fu80a0u5382u655eu7545u5531u5021u4f25u9b2fu82ccu83d6u5f9cu6005u60ddu960au5a3cu5ae6u6636u6c05u9cb3","chao":"u8d85u6284u949eu671du5632u6f6eu5de2u5435u7092u600au7ec9u6641u8016","che":"u8f66u626fu64a4u63a3u5f7bu6f88u577cu5c6eu7817","chen":"u90f4u81e3u8fb0u5c18u6668u5ff1u6c89u9648u8d81u886cu79f0u8c0cu62bbu55d4u5bb8u741bu6987u809cu80c2u789cu9f80","cheng":"u6491u57ceu6a59u6210u5448u4e58u7a0bu60e9u6f84u8bdau627fu901eu9a8bu79e4u57d5u5d4au5fb5u6d48u67a8u67fdu6a18u665fu584du77a0u94d6u88ceu86cfu9172","chi":"u5403u75f4u6301u5319u6c60u8fdfu5f1bu9a70u803bu9f7fu4f88u5c3au8d64u7fc5u65a5u70bdu50bau5880u82aau830cu640bu53f1u54e7u557bu55e4u5f73u996cu6cb2u5ab8u6555u80ddu7719u7735u9e31u761bu892bu86a9u87adu7b1eu7beau8c49u8e05u8e1fu9b51","chong":"u5145u51b2u866bu5d07u5ba0u833au5fe1u61a7u94f3u825f","chou":"u62bdu916cu7574u8e0cu7a20u6101u7b79u4ec7u7ef8u7785u4e11u4fe6u5733u5e31u60c6u6eb4u59afu7633u96e0u9c8b","chu":"u81edu521du51fau6a71u53a8u8e87u9504u96cfu6ec1u9664u695au7840u50a8u77d7u6410u89e6u5904u4e8du520du61b7u7eccu6775u696eu6a17u870du8e70u9edc","chuan":"u63e3u5dddu7a7fu693du4f20u8239u5598u4e32u63beu821bu60f4u9044u5ddbu6c1au948fu9569u8221","chuang":"u75aeu7a97u5e62u5e8au95efu521bu6006","chui":"u5439u708au6376u9524u5782u9672u68f0u69cc","chun":"u6625u693fu9187u5507u6df3u7eafu8822u4fc3u83bcu6c8cu80abu6710u9e51u877d","chuo":"u6233u7ef0u851fu8fb6u8f8du955eu8e14u9f8a","ci":"u75b5u8328u78c1u96ccu8f9eu6148u74f7u8bcdu6b64u523au8d50u6b21u8360u5472u5d6fu9e5au8785u7ccdu8d91","cong":"u806au8471u56f1u5306u4eceu4e1bu506cu82c1u6dd9u9aa2u742eu7481u679e","cu":"u51d1u7c97u918bu7c07u731du6b82u8e59","cuan":"u8e7fu7be1u7a9cu6c46u64bau6615u7228","cui":"u6467u5d14u50acu8106u7601u7cb9u6decu7fe0u8403u60b4u7480u69b1u96b9","cun":"u6751u5b58u5bf8u78cbu5fd6u76b4","cuo":"u64aeu6413u63aau632bu9519u539du811eu9509u77ecu75e4u9e7eu8e49u8e9c","da":"u642du8fbeu7b54u7629u6253u5927u8037u54d2u55d2u601bu59b2u75b8u8921u7b2au977cu9791","dai":"u5446u6b79u50a3u6234u5e26u6b86u4ee3u8d37u888bu5f85u902eu6020u57edu7519u5454u5cb1u8fe8u902fu9a80u7ed0u73b3u9edb","dan":"u803du62c5u4e39u5355u90f8u63b8u80c6u65e6u6c2eu4f46u60eeu6de1u8bdeu5f39u86cbu4ebbu510bu5369u840fu5556u6fb9u6a90u6b9au8d55u7708u7605u8043u7baa","dang":"u5f53u6321u515au8361u6863u8c20u51fcu83eau5b95u7800u94dbu88c6","dao":"u5200u6363u8e48u5012u5c9bu7977u5bfcu5230u7a3bu60bcu9053u76d7u53e8u5541u5fc9u6d2eu6c18u7118u5fd1u7e9b","de":"u5fb7u5f97u7684u951d","deng":"u8e6cu706fu767bu7b49u77aau51f3u9093u5654u5d9du6225u78f4u956bu7c26","di":"u5824u4f4eu6ef4u8feau654cu7b1bu72c4u6da4u7fdfu5ae1u62b5u5e95u5730u8482u7b2cu5e1du5f1fu9012u7f14u6c10u7c74u8bcbu8c1bu90b8u577bu839cu837bu5600u5a23u67e2u68e3u89ccu7825u78b2u7747u955du7f9du9ab6","dian":"u98a0u6382u6ec7u7898u70b9u5178u975bu57abu7535u4f43u7538u5e97u60e6u5960u6dc0u6bbfu4e36u963du576bu57ddu5dc5u73b7u765cu766bu7c1fu8e2e","diao":"u7889u53fc