gpt4 book ai didi

javascript - 无法显示表情值

转载 作者:行者123 更新时间:2023-12-01 05:44:27 25 4
gpt4 key购买 nike

Textarea 无法预览图像,因此我将其设置为 backgroundcolor transparent 并在其后面设置另一个 div预览文本区域的值。

现在,当我单击右侧表情符号图标(在我的下面的示例中)切换以显示全部并单击其中任何一个进行添加时,它无法显示表情符号值(仅透明插入)但已提交。请问我哪里错了?

这里。如果我写一些东西它的显示效果很好。但是在文本区域上书写并单击插入任何表情符号后,它也无法工作。可能这些问题也与上面有关。

请帮帮我?

var smileys = {
':)': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
':-)': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
':D': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
};

function smilyMe(msg) {
msg = msg.replace(/(?:\r\n|\r|\n)/g, '<br />');
for (var key in smileys) {
msg = msg.replace(key, smileys[key]);
}
return msg;
}
$(document).ready(function() {
$(".chat > textarea").bind("keyup", function(e) {
$(".chat > div").html(smilyMe($(".chat > textarea").val()));
});
$('#maintbox').on('keyup',function() {
$(this).css('height','auto');
$(this).css('height',Math.max(this.scrollHeight)+'px');
});
$('#showhide_emobox').click(function(){
$('#emobox').fadeToggle();
$(this).toggleClass('active');
});
$(".embtn").click(function(event){
var prevMsg = $(".chat > textarea").val();
var emotiText = $(event.target).attr("alt");
$(".chat > textarea").html(prevMsg + emotiText);
});
$('textarea').elastic();
});
#maintbox {
position:relative;
border: 2px solid #ccc;
min-height: 50px;
width: 450;
top:100px;
}
div.chat {
width: 100%;
}
.preview {
max-width: 400px;
font-family:Times New Roman, Times, serif;
font-size:14px;
color:#000000;
position:absolute;
top:0; left:0; z-index:997;
}
div.chat > textarea {
font-family:Times New Roman, Times, serif;
font-size:14px;
margin-left:-2px;
margin-top:-2px;
margin-bottom:2px;
min-height: 50px;
width: 510px;
resize:none;
float:left;
position:absolute; color:transparent;
top:0; left:0; z-index:998; background: transparent;
}
.em {
position:relative;
margin:1px 2px;
float:right;
height:20px;
width:20px;
text-align:center;
}
.em img {
margin-top:1px;
cursor:pointer;
color:white;
display:block;
transition:all 1s ease;
}
#emobox {
background:#fff;
display:none;
position:absolute;
width:200px;
bottom:25px;
left:-176px;
border: 2px solid #ccc;
white-space:nowrap;
}
#emobox img {
float:left;
position:relative;
display:inline-block;
margin:5px 5px;
}
<div id="maintbox">
<div class="chat">
<div class="preview"></div>
<textarea name="comment" rows="2" tabindex="4" id="comment" placeholder="Type here..."></textarea>
</div>

<div align="right"><img src="https://cdn3.iconfinder.com/data/icons/fez/512/FEZ-05-128.png" width="25" alt="" id="uploadMedia" style="padding:2px;cursor:pointer;" />
<div class="em">
<img src="http://simpleicon.com/wp-content/uploads/big-smile-256x256.png" width="25" id="showhide_emobox"/>
<div id="emobox">
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":)" class="embtn" />
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":-)" class="embtn" />
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":D" class="embtn" />
</div>
</div>
</div>

<script type='text/javascript' src='https://c0d3.googlecode.com/files/jquery-latest.pack.js'></script>
<script src="https://jquery-elastic.googlecode.com/svn-history/r30/trunk/jquery.elastic.source.js"></script>

最佳答案

仅在文本区域的 keyup 事件时将文本和表情符号复制到预览框。当您选择表情符号时,您也需要执行此操作,只需将以下行添加到表情符号点击处理程序中即可:

$(".chat > div").html(smilyMe($(".chat > textarea").val()));

这是您的固定代码段

var smileys = {
':)': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
':-)': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
':D': '<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" border="0" alt="" />',
};

function smilyMe(msg) {
msg = msg.replace(/(?:\r\n|\r|\n)/g, '<br />');
for (var key in smileys) {
msg = msg.replace(key, smileys[key]);
}
return msg;
}
$(document).ready(function() {
$(".chat > textarea").bind("keyup", function(e) {
$(".chat > div").html(smilyMe($(".chat > textarea").val()));
});
$('#maintbox').on('keyup',function() {
$(this).css('height','auto');
$(this).css('height',Math.max(this.scrollHeight)+'px');
});
$('#showhide_emobox').click(function(){
$('#emobox').fadeToggle();
$(this).toggleClass('active');
});
$(".embtn").click(function(event){
var prevMsg = $(".chat > textarea").val();
var emotiText = $(event.target).attr("alt");
$(".chat > textarea").html(prevMsg + emotiText);
$(".chat > div").html(smilyMe($(".chat > textarea").val()));
});
$('textarea').elastic();
});
#maintbox {
position:relative;
border: 2px solid #ccc;
min-height: 50px;
width: 450;
top:100px;
}
div.chat {
width: 100%;
}
.preview {
max-width: 400px;
font-family:Times New Roman, Times, serif;
font-size:14px;
color:#000000;
position:absolute;
top:0; left:0; z-index:997;
}
div.chat > textarea {
font-family:Times New Roman, Times, serif;
font-size:14px;
margin-left:-2px;
margin-top:-2px;
margin-bottom:2px;
min-height: 50px;
width: 510px;
resize:none;
float:left;
position:absolute; color:transparent;
top:0; left:0; z-index:998; background: transparent;
}
.em {
position:relative;
margin:1px 2px;
float:right;
height:20px;
width:20px;
text-align:center;
}
.em img {
margin-top:1px;
cursor:pointer;
color:white;
display:block;
transition:all 1s ease;
}
#emobox {
background:#fff;
display:none;
position:absolute;
width:200px;
bottom:25px;
left:-176px;
border: 2px solid #ccc;
white-space:nowrap;
}
#emobox img {
float:left;
position:relative;
display:inline-block;
margin:5px 5px;
}
<div id="maintbox">
<div class="chat">
<div class="preview"></div>
<textarea name="comment" rows="2" tabindex="4" id="comment" placeholder="Type here..."></textarea>
</div>

<div align="right"><img src="https://cdn3.iconfinder.com/data/icons/fez/512/FEZ-05-128.png" width="25" alt="" id="uploadMedia" style="padding:2px;cursor:pointer;" />
<div class="em">
<img src="http://simpleicon.com/wp-content/uploads/big-smile-256x256.png" width="25" id="showhide_emobox"/>
<div id="emobox">
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":)" class="embtn" />
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":-)" class="embtn" />
<img src="http://www.html5gamedevs.com/public/style_emoticons/default/wacko.png" alt=":D" class="embtn" />
</div>
</div>
</div>

<script type='text/javascript' src='https://c0d3.googlecode.com/files/jquery-latest.pack.js'></script>
<script src="https://jquery-elastic.googlecode.com/svn-history/r30/trunk/jquery.elastic.source.js"></script>

关于javascript - 无法显示表情值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28230726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com