使用jQuery将图像标记附加到contenteditable div中

时间:2013-08-22 08:53:12

标签: jquery contenteditable

我有微笑和满足div的div:

<div id="smiles">
    <img src="/img/smile/acute.gif">
    <img src="/img/smile/aggressive.gif">
    <img src="/img/smile/bad.gif">
    <img src="/img/smile/biggrin.gif">
    <img src="/img/smile/blum1.gif">
    <img src="/img/smile/blush.gif">
    <img src="/img/smile/boredom.gif">
    <img src="/img/smile/bye.gif">
    <img src="/img/smile/clapping.gif">
    <img src="/img/smile/congratulate.gif">
    <img src="/img/smile/cool.gif">
    <img src="/img/smile/cray.gif">
    <img src="/img/smile/dance.gif">
    <img src="/img/smile/dance2.gif">
</div>
<div contenteditable="false" unselectable="true" style="disabled:true" id="message_text">
    <img src="/img/smile/boredom.gif">
</div>

和jQuery代码:

    $("#smiles").on('click', 'img', function () {
        if ($('#message_text').prop("contentEditable")) {
            $('#message_text').append($(this).clone()).focus();
        }
    });

我也在尝试

if ($('#message_text').attr("contentEditable"))

如果div是contentEditable但IF不起作用

,我想要追加微笑

1 个答案:

答案 0 :(得分:1)

  $("#smiles img").click(function(){
    if ($('#message_text').attr("contentEditable")=="false")
{
       $('#message_text').append($(this));

        }
  });