为了账号安全,请及时绑定邮箱和手机立即绑定

尝试将 html 元素设置为 google trend embed 时出现 PHP 错误

尝试将 html 元素设置为 google trend embed 时出现 PHP 错误

PHP
忽然笑 2023-09-15 17:34:02
当尝试使用 jquery 将元素的 html 属性设置为 google trend embed 时,我收到错误。<!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><?phpecho "<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>";?>错误消息-“未捕获的语法错误:无效或意外的标记”
查看完整描述

1 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

  1. 您不需要使用echo函数打印输出。它会将自身嵌入到指定的 div 中。这里的div id是google_trends

  2. 您显示/隐藏google_trends div 的要求将通过使用Ready函数初始化 jquery 来满足。页面加载后,它将删除 隐藏类并显示谷歌趋势请求结果。

  3. 使用renderExploreWidgetTo函数而不是renderExploreWidget。通过这个,您可以定义要在其中显示输出的 div id。

尝试以下代码。

<!DOCTYPE html>

<html>

<head>

    <title>Titlw</title>

    

</head>

<body>

    <div class="hide" id="google_trends"></div>



    <script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>

    <script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/1328_RC04/embed_loader.js"> </script>

 </body>

</html>


<script type="text/javascript">

$( document ).ready(function() {

    $('#google_trends').removeClass('hide');

    trends.embed.renderExploreWidgetTo(google_trends,'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>

注意:这是一个独立的代码,因为我添加了 jquery CDN 链接和 google trend 的 ember_loader js 文件。


查看完整回答
反对 回复 2023-09-15
  • 1 回答
  • 0 关注
  • 59 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信