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

Cleverly use replace to replace text emoticons with images_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:52:081936browse

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
Statement:
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