繁体   English   中英

html代码未运行jquery问题

[英]html code not running jquery issue

HTML代码未运行! 这里item.m =“一些html代码”,但是它显示为纯文本,而不是运行html。 我很困惑现在该怎么办..

$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+$.parseHTML(item.m)+'</span></div>');

完整代码:

$.ajax({
  url: "chat.php?action=chatheartbeat",
  cache: false,
  dataType: "json",
  success: function(data) {

    $.each(data.items, function(i,item){
        if (item)   { // fix strange ie bug

            chatboxtitle = item.f;

            if ($("#chatbox_"+chatboxtitle).length <= 0) {
                createChatBox(chatboxtitle);
            }
            if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
                $("#chatbox_"+chatboxtitle).css('display','block');
                restructureChatBoxes();
            }

            if (item.s == 1) {
                item.f = username;
            }

            if (item.s == 2) {
                $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
            } else {
                newMessages[chatboxtitle] = true;
                newMessagesWin[chatboxtitle] = true;
                $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+$.parseHTML(item.m)+'</span></div>');
            }

            $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
            itemsfound += 1;
        }
    });

响应数据为<a href='../chat/file/6717_1_work.txt'>work.txt</a>但它显示为文本而不是超链接。

的jsfiddle

显然,您需要删除$ .parseHTML,它将起作用

$("div").append('<span class="chatboxmessagecontent">'+("<a href='../chat/file/6717_1_work.txt'>work.txt</a>")+'</span></div>');

如您在此jsFiddle中的代码所见,它与$ .parseHTML兼容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM