【问题标题】:How to show image code instead of image path in phonegap如何在phonegap中显示图像代码而不是图像路径
【发布时间】:2015-08-07 04:42:56
【问题描述】:

我正在电话间隙中制作聊天应用程序,并且我想插入明喻,我已从文本区域插入明喻并显示在正文中,但问题是当我单击明喻时文本区域显示的是整个路径,而不是标题,比如我们写的笑:D,它显示了笑的明喻。当我点击笑时,它会显示图像的整个路径,但不会显示:D(我想要的)。这是我的代码:

 <textarea name="txtmessage" style=" width: 82%; height: auto; outline-color: none;" id="txtmessage" placeholder="write your text here..."></textarea>
                            <div class="em">
                                <img src="http://simpleicon.com/wp-content/uploads/big-smile-256x256.png" width="25" id="showhide_emobox" />
                                <div id="emobox">
                                    <img alt=":)" border="0" src="emotions/emoticon-happy.png" />
                                    <img alt=":(" border="0" src="emotions/emoticon-unhappy.png" />
                                    <img alt=":o" border="0" src="emotions/emoticon-surprised.png" />
                                </div>

                            </div>

 $('#emobox img').live("click",function () {
            var smiley = $(this).attr('alt');
            var test = $(this).attr('src');
            var tst1 = '<img alt=' + smiley + ' border=0 src=' + test + ' />'
            ins2pos(tst1, 'txtmessage');
        });

【问题讨论】:

    标签: javascript jquery cordova


    【解决方案1】:

    如果你只想插入图片标签的alt,为什么要使用src构造一个新字符串?为什么不这样做呢?

     $('#emobox img').live("click",function () {
            var smiley = $(this).attr('alt');
            ins2pos(smiley, 'txtmessage');
    });
    

    【讨论】:

    • 我知道这仅适用于标题,但我也想要那里的图像(模拟),但在文本区域我不想显示路径而是标题,当我点击发送按钮时它应该在聊天正文中显示明喻,现在显示上面的代码明喻,但在文本区域中显示整个路径而不是标题
    • 您无法将图像添加到textarea。您可以将其设为可编辑的内容 div stackoverflow.com/questions/3793090/… 或另一种解决方案是使用 html 实体而不是图像
    猜你喜欢
    • 2017-03-14
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 2017-08-18
    • 1970-01-01
    • 2022-07-05
    • 1970-01-01
    相关资源
    最近更新 更多