VAR faceDir = "images/"; //配置表情目录
var ifr
ameDocument = null;
var iframeWindow = null;
var isIe = false;
$.
each($("
#faceList>li"), function(){ //展现表情
var node = document.createElement("img");
node.
classname = $(this).attr("class");
node.src = faceDir+$(this).
html();
this.innerHT
ML = "";
this.ap
PEndChild(node);
});
<iframe id="Ed
IT" frameborder="0"></iframe>
iframeDocument.write("<html><body style=\"word-wrap:
break-word;text-align: left; background-color: #fff; border:1px solid #CCC; m
argin:0px; padding:0px;overflow:hidden;\"></body></html>");
$("#faceList>li").click(function(){
var $this = $(this);
var $thisImg = $(this).find("img:eq(0)"); //当前点击的表情(IMG标记)
document.getElementById("Edit").contentWindow.focus(); //使编辑区域得到
焦点 var r = null;
if(document.selection) //处理兼容性问题
{
//把表情放入iframe
r = iframeDocument.selection.createRange();
iframeDocument.selection.empty();
r.pasteHTML($thisImg[0].parentNode.innerHTML.toString());
}
else if(window.getSelection)
{
r = iframeWindow.getSelection().getRangeAt(0);
iframeWindow.getSelection().removeAllRanges();
var node = document.createElement("img");
node.className = $thisImg.attr("class");
node.src = $thisImg.attr("src");
r.surroundContents(node);
}
});
function GeteEditData()
{
var edit = iframeDocument.
getelementsbytagname("body")[0].innerHTML;
//在内存中Copy一个该节点副本,以保全文档流格式
var str = new String(edit);
var $content = $("<div>"+str+"</div>");
var imgNode = $("#faceList img");
$.each(imgNode, function(){
var mark= "/:"+$(this).attr("class").toString();
var fs = $content.find("."+$(this).attr("class").toString());
if(fs!=null
&&fs[0]!=un
defined)
{
fs.replaceWith(mark);
}
});
}