由于某些原因,当我先使用json_encode
,然后使用JSON.parse
来获取JS -HTML中的数组时,字符串只能获取字符串的结束标记。举个例子:
$php_array = array (
"title" => "this is a <strong>title</strong>",
"text" => "<p>this is some text</p>"
)
<div id="data"><?php echo json_encode($php_array); ?></div>
然后在JS中:
const someArray = $('#data').text();
const data = JSON.parse(someArray);
输出如下所示:
0:
title: "this is a title</strong>",
text: "this is some text</p>"
你知道是什么原因造成的吗?
https://stackoverflow.com/questions/51805033
复制相似问题