我想在html文檔中添加谷歌趨勢圖。問題是我必須抓住點擊關鍵字並將其傳遞到谷歌趨勢功能,因此它可以返回數據作爲點擊關鍵字。但由於某種原因,當我打電話谷歌趨勢功能(named-TIMESERIES)內.click範圍它只加載圖表不是整個HTML,所以我必須從外部調用此功能.click範圍。原因是計時問題。請看看這種時機的解決方案issue solution here我不能用我的代碼實現這個解決方案。如果你能,那麼它真的幫助我。在此先感謝使用.click()全局變量範圍內的javascript時間問題
<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>
你能用我現有的代碼來實現它嗎? –
@JohnLk已更新。 – Naltroc