Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将Div Content设置为JSON对象的属性会导致在屏幕上显示html标记_Jquery_Html_Json_Umbraco - Fatal编程技术网

Jquery 将Div Content设置为JSON对象的属性会导致在屏幕上显示html标记

Jquery 将Div Content设置为JSON对象的属性会导致在屏幕上显示html标记,jquery,html,json,umbraco,Jquery,Html,Json,Umbraco,我有一个umbraco宏,可以在 这一切都很好,但当我尝试将div的内容设置为JSON对象的属性(从隐藏div中的原始html解析)时,输出将显示实际文本,而不是将其解释为html。您可以通过单击演示url中的互动程序来查看结果 总之: var jsonString = $(dataElementId).html(); var data = $.parseJSON(jsonString); //Set Properties of Player with the selected project

我有一个umbraco宏,可以在

这一切都很好,但当我尝试将div的内容设置为JSON对象的属性(从隐藏div中的原始html解析)时,输出将显示实际文本,而不是将其解释为html。您可以通过单击演示url中的互动程序来查看结果

总之:

var jsonString = $(dataElementId).html();
var data = $.parseJSON(jsonString);

//Set Properties of Player with the selected project:
$("#projectCompanyLogo").attr("src", data.ProjectCompanyLogoUrl);
$("#smallTitlePg").html(data.SmallTitle);
$("#mainTitlePg").html(data.MainTitle);

//Change the content of a div to the data in project description, should show as pure html:     
$("#flexScrollDynamicContent").html(unescape(data.ProjectDescription).replace('"',''));
$("#projectContent").attr("style", data.RightColumnBg);
不知道我做错了什么。。。但是当设置内容时,您会在屏幕上看到物理的
标记,而不是将其呈现为HTML。

您可以执行以下操作:

$("#flexScrollDynamicContent").html($('<div/>').html(data.ProjectDescription).text());
$(“#flexScrollDynamicContent”).html($('').html(data.ProjectDescription.text());
这本质上使jQuery解码html实体(在Json字符串中),例如:

$('<div/>').html("&lt;p&gt;Hello&lt;/p&gt;").text();
$('').html(“pHello/p”).text();
给出:

<p>Hello</p>
你好


非常感谢。。。完全正确我不熟悉jquery的东西。。刚从服务器端/web表单世界出来!