2014-04-24 16 views
0

我從數據庫獲取動態數據並使用html()函數附加到我的html。 一切正常,但當動態數據包含'>'或'<'標籤作爲數據時,腳本將其作爲html標籤並且數據和腳本中斷。使用html加載動態數據()在加載的內容具有特殊字符時打破腳本

function showKeywordActivity(e, t, n, r, i) { 
    var s = $(e).find("input.keywordFrequencyIdList").val(); 
    var o = $(e).find("input.keywordId").val(); 
    var u = $(e).find(".keywordValue").val(); 
    $(".hashKeyword").text("#" + u); 
    $("#tabs-1").html('<div class="innerBox"><div class="innerBoxcontent scroll"><div class="loadingWrap"><div class="loading"></div></div></div><div class="dashboardBottombox"></div></div>'); 
    $.ajax({type: "POST",url: "url",data: {pageUrlHandle: n,keywordId: o,pattern: u,serviceType: t,startDate: r,endDate: i,keywordType: $("#keywordActivityTypeFilter").val(),keywordType: $("#activityFilter").val()},dataType: "html",async: true,success: function(t) { 
      $(e).css("background", "#F8FAFF"); 
      $("#tabs-1").html(t); 
      $(".scroll").each(function() { 
       $(this).mCustomScrollbar({theme: "light",advanced: {updateOnBrowserResize: true,updateOnContentResize: true,autoExpandHorizontalScroll: false,autoScrollOnFocus: true}}) 
      }) 
     },error: function(e, t) { 
     }}) 
} 

如何解決這個錯誤。任何人請幫助我

回答

2

使用$("#tabs-1").text(t);而不是.html();來轉義特殊字符。

0

如果你想html內容放置一些標籤內(可以說#target),然後

$('#target').html(content); 

如果要放置text內容,然後

$('#target').text(content);