How JavaScript gets the first letter of Chinese pinyin and quickly finds pages by Pinyin first letter

Source: Internet
Author: User

Implementation effect:

Figure I:

Figure II:

In this example, the Chinese character string "Take care of Yourself", with three words being pronunciation, so the alert dialog box shows a combination of multiple pronunciations;

How to achieve it?

How to achieve through Pinyin first letter quickly find the content of Chinese in the page?

The principle of the process is this: for example, to make a quick search of some names, when the page is loaded, set up an index of all the names, generate the corresponding relationship between the first letter and the name of pinyin; then listen for keyboard events, and when the user presses the keyboard, according to which letter the key is worth, Then traverse the index to see if the same phonetic initials exist;

It also implements the ability to find by letter combination, the principle is this: when the user button, we record the button time, if two consecutive key intervals less than a second, it is considered a combination of query, the current key value added before the key value, not much said, on the code!

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.