---
title: "jquery 选择表情插件"
author: "dh189"
date: "2010-08-04T12:26:31Z"
tags: ["CSS", "F#", "HTML", "jQuery", "prototype"]
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2010-08-04T12:26:31Z"
id: 728724
url: "https://dh189.iteye.com/blog/728724"
---

效果如下： \[img]http://dl.iteye.com/upload/attachment/287887/b85a1319-0e20-3c98-bd58-8b5fc4cb3c9a.jpg\[/img] \[img]http://dl.iteye.com/upload/attachment/287889/a51b277c-889d-3252-93f0-6797249dfc5f.jpg\[/img] face.js \[code="java"] function Face(id){this.ojb=$("#"+id);this.oid=id; this.create()} //头像路径 var faceUrl="gif/"; //定义头像数量 var faceNums=39; Face.prototype.create =function(){ var oid=this.oid; var my\_face=$("body").find("\[name=my\_face\_"+oid+"]"); var msg="" msg+="

"; if(my\_face.length==0){ var \_div=""; $("body").append($(\_div).html(msg)); }else{ my\_face.html(msg); } $("#faceContent\_"+oid).html(""); var \_str=""; for(var i=1;i&lt;=faceNums;i++){ var str=faceUrl+"F\_"+i+".gif"; \_str+="[![](+str+)](javascript:void%280%29)"; } $("#faceContent\_"+oid).html(\_str); } Face.prototype.close=function(id){ if(!id){ $("#my\_face\_"+this.oid).html(""); }else{ $("#my\_face\_"+id).html(""); } } function removeFace(id){ $("#faceContent\_"+id).hide(); $("#my\_face\_"+id).html(""); } //控制表情区位置 Face.prototype.show=function(){ var O=this.ojb; var oid=this.oid; var top=O.offset().top; var left=O.offset().left; var h=O.height(); $("#faceContent\_"+oid).css("top",(top+h)+"px").css("left",left+"px").show(); $("#faceContent\_"+oid+" img").unbind("click").bind("click",function(){ var \_v=O.val(); \_v+=$(this).attr("fn"); O.val(\_v); $("#faceContent\_"+oid).hide(); }); } //重新显示 function reShow(id){ var O=$("#"+id); var top=O.offset().top; var left=O.offset().left; var h=O.height(); $("#faceContent\_"+id).css("top",(top+h)+"px").css("left",left+"px"); } //替换页面中的表情代码为图片 function convertImg(val){ return val.replace(/\\\[@/g, "![](+faceUrl+)");; } \[/code] 测试代码如下： \[code="java"] New Document

\[/code]