【发布时间】:2020-08-05 21:21:43
【问题描述】:
尝试使用 jquery 将元素的 html 属性设置为 google 趋势嵌入时出现错误。
<!DOCTYPE html>
<html>
<head>
<title>Titlw</title>
</head>
<body>
<div class="hide" id="google_trends"></div>
</body>
<script type="text/javascript">
/*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */
</script>
</html>
<?php
echo "
<script>
$('#google_trends').removeClass('hide');
$('#google_trends').html('<script type=\"text/javascript\" src=\"https://ssl.gstatic.com/trends_nrtr/2213_RC01/embed_loader.js\"></script> <script type=\"text/javascript\"> trends.embed.renderExploreWidget(\"TIMESERIES\", {\"comparisonItem\":[{\"keyword\":\"a\",\"geo\":\"\",\"time\":\"today 5-y\"}],\"category\":0,\"property\":\"froogle\"}, {\"exploreQuery\":\"date=today%205-y&gprop=froogle&q='a'\",\"guestPath\":\"https://trends.google.com:443/trends/embed/\"});</script>');
</script>";
?>
错误信息 -
“未捕获的 SyntaxError:无效或意外令牌”
【问题讨论】:
-
为什么还要让 PHP 参与进来? (该错误也读起来像开发者控制台错误,而不是 PHP/服务器端)
-
你为什么要这样做?当然,您可以简单地将脚本添加到 html。为什么要使用 JQuery?为什么要使用 PHP?
标签: php html jquery ajax google-trends