可以利用此方法 让网页更加精彩 比如制作一个js表情系统

制作表情系统思路

比如表情输出的代码为[emt]16[/emt]我们需要做的就是用replace替换掉16前后的字符

可以用以下的方法

<div id="biaoqing">[emt]16[/emt]</div>
<!--上面是显示区域-->

<script type="text/javascript">

// 替换代码为表情
window.onload=function(){
var div = document.getElementById('biaoqing');
var html = div.innerHTML;
div.innerHTML = html.replace(/(\[emt])/g,"<img src="+"/img/").replace(/(\[)/g,"").replace(/(\/emt])/g,".gif />");
}
</script>

 

Last modification:July 12, 2018
If you think my article is useful to you, please feel free to appreciate