How to highlight friends name in Facebook status update box (textarea)?

前端 未结 3 1227
不知归路
不知归路 2021-01-31 06:55

In Facebook status update box, when I type @ and start typing and choose a name, say Steven Gerrard, from the friends list suggested by fb, my friend\'s name is highlighted in t

3条回答
  •  迷失自我
    2021-01-31 07:13

    After reviewing the way of Facebook do this, I see that the text shown on the screen is:

    Ws Dev is good
    

    That span is put in a table (with lots of div container), which is style accordingly.

    So I think this is the process:

    1. When you type in the box, Facebook does have a textarea that capture what you type, but use javascript to show the typed HTML content in a table.

    2. When you submit, the formatted content in a hidden input (that you already spot in the question) get submitted. It's like "@[100001915747xxx:Steven Gerrard] is awesome".

    3. When the formatted message submit, it is saved to the database. Everytime the page get loaded, from the saved message the HTML is composed and return.

    To get the similar effect, you can use any jQuery autocomplete plugin.

提交回复
热议问题