Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

javascript - type @, show a name list like facebook status box

in facebook status box, if you type '@', then a list of friends' names appear. I am trying to implement such a status box.

But the problems are:

On typing '@', where should the 'div's location be and how to show the list? I just can't make anything out of it.

I went through this question of SOF, but that actually does not discuss that.

Anybody there to shed light on it as much as possible?

My choice is jquery.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From a quick glance at facebook, it appears that there is a <div> tag that renders the highlighted content along side the text content.

The text is captured one keystroke at a time by onKeyUp events on the <textarea> element (transparent and overlayed on top of the div with the visible content) and transposed into the <div> element. When examining the key up events, simply check if the key is '@' and fire the menu event.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...