Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在contenteditable div上编写带有表情符号的文本_Javascript_Jquery - Fatal编程技术网

Javascript 如何在contenteditable div上编写带有表情符号的文本

Javascript 如何在contenteditable div上编写带有表情符号的文本,javascript,jquery,Javascript,Jquery,我将显示表情的textarea更改为divcontenteditable,但只需用文本输入表情的值。所以我使用jQuery.bind 现在,当我在textarea上写入任何内容时,我无法在contenteditable div上输入任何文本 这是我的作品:(这里888是我所有的php。$id.) var smileys={ ':)': '', ':-)': '', “:D”:”, }; 函数escapeRegExp(str){ 返回str.replace(/[\-\[\]\/\{\\}(\)\

我将显示表情的
textarea
更改为
divcontenteditable
,但只需用文本输入表情的值。所以我使用jQuery
.bind

现在,当我在textarea上写入任何内容时,我无法在
contenteditable div
上输入任何文本

这是我的作品:(这里888是我所有的php
。$id.

var smileys={
':)': '',
':-)': '',
“:D”:”,
};
函数escapeRegExp(str){
返回str.replace(/[\-\[\]\/\{\\}(\)\*\+\?\.\\\^\$\\\\\\\\\\;]/g,“\$&”);
}
函数smilyMe(msg){
msg=msg.replace(/(?:\r\n |\r |\n)/g,“
”); for(smileys中的var键){ msg=msg.replace(新的RegExp(escapeRegExp(键),“g”),smileys[键]; } 返回味精; } $(文档).ready(函数(){ $(“#注释”).bind(“键控”,函数(e){ var EID=$(this.attr('class').replace('com',''); $(“.com”+EID.html(smilyMe($(“.com”+EID.html()); }); });
#maintbox{
顶部:50px;
位置:相对位置;
最小高度:38px;
宽度:100%;
}
聊天室{
宽度:100%;
}
#评论{
字体系列:泰晤士报新罗马,泰晤士报,衬线;
字体大小:12px;
最小高度:25px;
颜色:#000;
顶部:0;左侧:0;z索引:998;背景:透明;
边框:2个实心#ccc;
位置:相对位置;
浮动:左;
宽度:100%;
保证金:0;
调整大小:无;
右边填充:50px;
-webkit框大小:边框框;
-moz框大小:边框框;
框大小:边框框;
}

希望这对你的伴侣有所帮助:)


谢谢您,先生。已用html更新,但在使用“:”文本区域光标从头开始写入任何文本后。请检查此链接。如果您发现答案有用,请将答案投票给其他人,以便对其他人也有帮助。
$(document).ready(function() {
  $("#comment").bind("keyup", function(e) {
    var EID = $(this).attr('class').replace('com','');
    $(".com"+EID).html(smilyMe($(".com"+EID).html()));  //Replaced .val() to .html()
  });
});