因为我被困住了,我希望能有一双额外的眼睛。
该代码可以正常工作,因此当您单击表情符号时,:wow:
将显示在输入中,但由于未知原因,我根本无法使其正常工作:
//Smiley to Input
$(function () {
function caretPos() {
var el = document.getElementById("chatline");
var pos = 0;
// IE Support
if (document.selection) {
el.focus();
var Sel = document.selection.createRange();
var SelLength = document.selection.createRange().text.length;
Sel.moveStart('character', -el.value.length);
pos = Sel.text.length - SelLength;
}
// Firefox support
else if (el.selectionStart || el.selectionStart == '0') pos = el.selectionStart;
return pos;
}
$('#emoticons a').click(function () {
var smiley = $(this).attr('title'),
caretPos = caretPos(),
strBegin = $('#chatline').val().substring(0, caretPos),
strEnd = $('#chatline').val().substring(caretPos);
$('#chatline').val(strBegin + " " + smiley + " " + strEnd);
});
//Hide and Show Smiley Box
var $container = $('#smiley-container');
$('#inputsmile').click(function () {
$container.toggleClass('smileysclosed smileysopen');
});
$(document).click(function (event) {
if ($container.hasClass('smileysopen') && !$(event.target).closest('.smileysopen, #inputsmile').length) {
$container.toggleClass('smileysclosed smileysopen');
return false;
}
});
});