Home > Web Front-end > JS Tutorial > Cleverly use replace to replace text emoticons with images_javascript skills

Cleverly use replace to replace text emoticons with images_javascript skills

WBOY
Release: 2016-05-16 16:52:08
Original
1968 people have browsed it

A common effect on Weibo or forums. When you select an emoticon and insert it into the text field, a string similar to [haha] is displayed. The following is a method to convert the emoticon string into a picture emoticon

Copy code The code is as follows:

abc


Copy code The code is as follows:

var face ={'[haha]': '','[sweat]':''} //See the end of this article for complete qq expressions

var reg = /[. ?]/g;

var str = '[haha]abc[sweat][ Sweat]'; //Here is the value of the text field obtained. For simplicity, strings are used directly.

str = str.replace(reg,function(a,b){

return face[a];

});

document. getElementById('test').innerHTML = str;

qq emoticon package and corresponding face object: http://pan.baidu.com/s/1qWPQbBu
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template