jQuery的的.text不会呈现HTML元素到DOM [英] jquery .text doesn't render HTML elements into the DOM
本文介绍了jQuery的的.text不会呈现HTML元素到DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我加载图片列表到一个div使用jQuery的下列位:
I am loading a list of images into a div with the following bit of jQuery :
var jewellerDdl = "<%= JewellerDropDownList.ClientID %>";
var filter = $("#" + jewellerDdl).val();
$.ajax({
type: "POST",
url: "popup.aspx/GetJewellerAssets",
contentType: "application/json; charset=utf-8",
data: '{"jewellerId":' + filter + '}',
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded(result) {
$("#divEntryDisplay").text(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' - ' + result.statusText);
}
我回来的字符串是&LT; UL&GT;
包含一些图片
然而,到.text方法犯规将它们添加到DOM。相反,它只是打印的HTML作为内文的&LT; DIV&GT;
称为divEntryDisplay
However, the .text method doesnt add them to the dom. Instead it just prints the HTML as text inside the <div>
called divEntryDisplay
我做了什么错?
推荐答案
您确实应该使用HTML方式(参见文献这里:的 http://docs.jquery.com/Attributes/html )
You should indeed use the html method (cf. documentation here : http://docs.jquery.com/Attributes/html)
这让你的函数是这样的:
Which makes your function look like this:
function AjaxSucceeded(result) {
$("#divEntryDisplay").html(result.d);
}
这篇关于jQuery的的.text不会呈现HTML元素到DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文