2015-05-25 53 views
0

我在手机间隙中制作聊天应用程序,并且我想插入明文,我从文本区域插入了明文,并将其显示在正文中,但问题是,当我点击明文表单文本区域时,它显示的是整个路径而不是标题,就像我们写的笑声一样: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'); 
     }); 

回答

0

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

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

我知道这仅适用于冠军,但我也想图像(比喻)那边,但在文字区域我不想显示路径,但标题,当我在发送键单击它应该显示的比喻在聊天正文中,现在显示上面的代码明文,但在文本区域显示的是整个路径而不是标题 –

+0

您不能将图像添加到'textarea'。你可以使它成为可编辑的'div'内容http://stackoverflow.com/questions/3793090/html-is-there-any-way-to-show-images-in-a-textarea或另一种解决方案是使用html实体而不是图像 – mpallansch

相关问题