打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
添加表情的代码

先在网上找到附件中的素材和部分源码,在稍加改造即可应用于评论框或者留言框旁边

 

 

下面代码和网上下载的素材是不一样的,素材中的是html控件,而下面则改成了服务器控件(为了能在后台获取文本框的值),先上代码,改动说明下面再说:

Html代码
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="common_test2" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <!--   
  5.     创建时间:08/25/2010 22:07:24   
  6.     说明:   
  7. -->  
  8. <html xmlns="http://www.w3.org/1999/xhtml" >  
  9. <head runat="server">  
  10.     <title>无标题页</title>  
  11. </head>  
  12. <body>  
  13.     <form id="form1" runat="server">  
  14.   
  15.   
  16. <div class="team_l">  
  17. <asp:TextBox ID="txtname" runat="server" Height="106px" TextMode="MultiLine"  
  18.         Width="182px" onkeydown=gbcount(this.form.gb_word,this.form.total,this.form.used,this.form.remain); onkeyup=gbcount(this.form.gb_word,this.form.total,this.form.used,this.form.remain);></asp:TextBox>  
  19. <br />  
  20. <div class="team_r" style="width:380px">  
  21.   <p><img src="../images/1.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-_-] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  22.       <img src="../images/2.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[@o@] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  23.       <img src="../images/3.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-|-] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  24.       <img src="../images/4.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[o_o] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  25.       <img src="../images/5.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[ToT] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  26.       <img src="../images/6.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[*_*] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  27.       <img src="../images/7.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-x-] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  28.       <img src="../images/8.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-_-zz] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  29.       <img src="../images/9.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[t_t] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  30.       <img src="../images/10.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-_-!] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  31.       <img src="../images/11.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:,] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  32.       <img src="../images/12.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:P] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  33.       <img src="../images/13.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:D] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  34.       <img src="../images/14.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:)] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  35.       <img src="../images/15.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:(] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  36.       <img src="../images/16.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:O] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  37.       <img src="../images/17.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:#] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  38.       <img src="../images/18.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:Z] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  39.       <img src="../images/19.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:0=] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  40.       <img src="../images/20.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/:P] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  41.       <img src="../images/21.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:$] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  42.       <img src="../images/22.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-.-] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  43.       <img src="../images/23.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/-_-] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  44.       <img src="../images/24.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:{] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  45.       <img src="../images/25.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[zz] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  46.       <img src="../images/26.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[|-_-|] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  47.       <img src="../images/27.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[-_-||] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  48.       <img src="../images/28.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:.] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  49.       <img src="../images/29.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:-Q] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  50.       <img src="../images/30.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[9_9] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  51.       <img src="../images/31.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:,.] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  52.       <img src="../images/32.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:?] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  53.       <img src="../images/33.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:-|] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  54.       <img src="../images/34.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:K] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  55.       <img src="../images/35.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:G] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  56.       <img src="../images/36.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:L] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  57.       <img src="../images/37.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:c] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  58.       <img src="../images/38.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:q] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  59.       <img src="../images/39.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[:Y] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  60.       <img src="../images/40.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/gs] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  61.       <img src="../images/41.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/sg] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  62.       <img src="../images/42.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/hp] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  63.       <img src="../images/43.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/ok] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  64.       <img src="../images/44.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/rain] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  65.       <img src="../images/45.gif" width="20" height="20" onClick="document.getElementById('txtname').value+='[/yin] ';document.getElementById('txtname').focus()" style="cursor:hand">  
  66.     </p>  
  67. </div>  
  68. <input type="reset" name="Submit2" value="重置">  
  69.     <asp:Button ID="submit" runat="server" Text="提交" OnClick="submit_Click" /><img src='../images/23.gif' width='20' height='20'/>  
  70. </div>  
  71. </form>  
  72. </body>  
  73. </html>  

原素材是获取name,而服务器控件没有name,故我们改成获取id

即将onClick="document.forms[0].gb_word.value(这句看不懂没有关系,是素材中的)改成

Html代码
  1. onClick="document.getElementById('txtname').value  

注:txtname为文本框的id值

 

这样就能在.cs文件中能取得文本框的值,从而添加到数据库中

 

注:服务器控件的id转成html的id后是一段很长的字符串,如果上面改动不能用,就把txtname改成对应生成的html页面的id即可

 

到此为止,展示页面的代码就改完了,接下来在后面进行处理,主要用到了replace(用法在网上搜一下就知道了,非常好用的)函数。

 

符号装成图片的方法

C#代码
  1. public string PictureSwap(string str)   
  2.    {   
  3.        string[] a = new string[] { "[-_-]""[@o@]""[-|-]""[o_o]""[ToT]""[*_*]""[-x-]""[-_-zz]""[t_t]""[-_-!]""[:,]""[:P]""[:D]""[:)]""[:(]""[:O]""[:#]""[:Z]""[:0=]""[/:P]""[:$]""[-.-]""[/-_-]""[:{]""[zz]""[|-_-|]""[-_-||]""[:.]""[:-Q]""[9_9]""[:,.]""[:?]""[:-|]""[:K]""[:G]""[:L]""[:c]""[:q]""[:Y]""[/gs]""[/sg]""[/hp]""[/ok]""[/rain]""[/yin]" };   
  4.        for (int i = 1; i <= 45; i++)   
  5.        {   
  6.            str = str.Replace(a[i - 1], "<img src='../images/" + i + ".gif' width='20' height='20'/>");   
  7.              
  8.        }   
  9.        Response.Write(str + "asadadadad<br/>");   
  10.        return str;   
  11.    }  

 参数str为要要转换的文字,比如说是整个留言的内容(其中加有类似([-|-])的符号)

 

用到了数组跟循环,也不太难就不说了

 

调用方法

Java代码
  1. string s = PictureSwap(txtname.Text.toString());  
 

s即为转换后的能显示图片的字符串

 

显示时有两种处理方式:

1.在存入数据库之前调用PictureSwap改变成图片地址

2、取出数据时调用PictureSwap转换成图片显示

 

这就看个人爱好,也看是哪一个使用频繁咯。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
js获取图片的原始尺寸
在ecshop首页增加对联广告的方法
收藏一些有用的JS代码
QQ 代码
QQ空间背景制作
Javascript实例练习——初级适用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服