我正在尝试在html文档上添加Google趋势图表。问题是我必须抓住点击关键字并将其传递给谷歌趋势功能,以便它可以将数据作为点击的关键字返回。但出于某种原因,当我在.click范围内调用谷歌趋势功能(命名为TIMESERIES)时,它只加载图表而不是整个html所以我必须从外部.click范围调用此函数。我该如何制作" categoryName"变量可用全球呢?任何想法?
但我的问题解决方案可能是available here。但我需要帮助用我现有的代码实现该解决方案。
<script>
function TIMESERIES(categoryName) {
return trends.embed.renderExploreWidget("TIMESERIES", {
"comparisonItem": [{
"keyword": categoryName,
"geo": "",
"time": "today 12-m"
}],
"category": 0,
"property": ""
}, {
"exploreQuery": "q=arts&date=today 12-m",
"guestPath": "https://trends.google.co.in:443/trends/embed/"
});
}
var categoryName = "";
$(".SearchMainCategory, .SearchSubCategory").click(function() {
categoryName = $(this).find("#Level1CatsName").val();
if (typeof categoryName === "undefined") {
categoryName = $(this).find("#Level2CatsName").val();
}
// TIMESERIES(categoryName) if i call this function from where then only this function (google trend chart actually) loads and page other contents not loading. so i need to call from outside then it works fine but i cant access "categoryName" variable from ourside.
});
TIMESERIES(categoryName);
</script>