1 回答

TA貢獻1906條經驗 獲得超10個贊
您不需要使用echo函數打印輸出。它會將自身嵌入到指定的 div 中。這里的div id是google_trends
您顯示/隱藏google_trends div 的要求將通過使用Ready函數初始化 jquery 來滿足。頁面加載后,它將刪除 隱藏類并顯示谷歌趨勢請求結果。
使用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 文件。
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報