JavaScript代码
  1. var Expression = (function () {  
  2.     return {  
  3.         images: [{className:'face_1',text: '微笑'},  
  4.             {className:'face_2',text: '害羞'},  
  5.             {className:'face_3',text: '喜欢'},  
  6.             {className:'face_4',text: '快哭了'},  
  7.             {className:'face_5',text: '爱心'},  
  8.             {className:'face_6',text: '擦汗'},{className:'face_7',text: '愤怒'},  
  9.             {className:'face_8',text: '可爱'},{className:'face_9',text: '小可怜'},{className:'face_10',text: '尴尬'},{className:'face_11',text: '呲牙'},  
  10.             {className:'face_12',text: '红唇'},{className:'face_13',text: '难过'},{className:'face_14',text: '亲亲'},{className:'face_15',text: '委屈'},  
  11.             {className:'face_16',text: '疑惑'},{className:'face_17',text: '拥抱'},{className:'face_18',text: '再见'},{className:'face_19',text: '咖啡'},  
  12.             {className:'face_20',text: '礼物'},{className:'face_21',text: '玫瑰'}],  
  13.         initBox: function ($selector) {  
  14.             $.each(Expression.images, function () {  
  15.                 if(this.className=="face_1" || this.className=="face_11"){  
  16.                     return true;  
  17.                 }  
  18.                 var li = $('<li></li>').data('express'this.text).append('<i class="icon '+this.className +'"></i>');  
  19.                 $selector.append(li);  
  20.             });  
  21.         },  
  22.         replaceHtml: function ($selector) {  
  23.             var html = $selector.html();  
  24.             $.each(Expression.images, function () {  
  25.                 var re = new RegExp("\\["+this.text+"\\]","g");  
  26.                 html = html.replace(re, '<i class="icon ' + this.className + '"></i>');  
  27.             });  
  28.             $selector.html(html);  
  29.         }  
  30.     }  
  31.   
  32. })();  
  33. $(function () {  
  34.     $('body').on("tap"'[data-express]'function () {  
  35.         var txt = $(this).data('express'), text = $('textarea');  
  36.         text.val(text.val() + '[' + txt + ']');  
  37.         var len = text.val().length;  
  38.         $('#provide').text(len + "/240字");  
  39.         text.focus();  
  40.     });  
  41. });  
  42.   
  43. Expression.replaceHtml($('#chat_list'));  
  44. Expression.initBox($('#face'))  
H5/JS/CSS | 评论(0) | 引用(0) | 阅读(3883)