weixin_33690963 2012-10-11 17:47 采纳率: 0%
浏览 154

jQuery .text()不显示HTML [重复]

This question already has answers here:
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2012-10-12 08:08:17Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

Possible Duplicate:
jquery .text doesn’t render HTML elements into the DOM

I have an AJAX function pulling an <img> tag from the server. My problem is, when I set the .text() property of a span on the page to that <img> tag, the HTML is not rendered. Rather, it just displays the tag as text.

Here is my code:

// jQuery
$.ajax({
  url: 'forms/scripts/getStatus.php',
  dataType: 'json',
  type: 'POST',
  data: {
      subfolderID:rowID
  },
  async: false,
  success: function(data){
      if(data.errorsExist == "Y"){
          alert(data.appError);
      }
      else{
          $("#trackStatus").text(data.status);    
      } 
  },
  error: function(){
      alert("Error! Could not retrieve tracking status");
  }
});

My HTML:

<td><span id="trackStatus"></span></td>

How can I get the img tag to render as HTML? Maybe I shouldn't be using a span with the .text() method...?

</div>
  • 写回答

3条回答 默认 最新

  • weixin_33737134 2012-10-11 17:48
    关注

    use .html() instead of .text()

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制