document.addEventListener('DOMContentLoaded', function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=" + "ranchi" + "&units=metric";
restClient(url);
document.querySelector('button').addEventListener('click', getWeatherByLocation);
});
function getWeatherByLocation() {`......do some work here..
var url=.....;
restClient(url);
}`
function restClient(url) {....//do some work here...
document.getElementById("data").innerHTML="Something to write"..;
}
restClient()
是ultmiatly的HTML
頁上寫的功能,現在的問題是第一次DOMContetnLoaded
的restClient
被調用,它寫在HTML
頁,然後下一行是執行其功能是:document.querySelector('button').addEventListener('click',getWeatherByLocation);
當某人觸發該按鈕,並最終功能restClient
是從getWeatherByLocation
函數, agin調用,但當某人再次觸發按鈕,如何再次執行第4行。函數restClient(url)如何不被調用whenevr DOMContentLoaded事件觸發?
我想在再次執行第4行之前,如果我沒有錯,第2,3行必須執行?
而且
如果'getWeatherByLocation'不會重新加載DOM,爲什麼會2號線和3被再次叫什麼名字?或者我想念你的問題? – DavidDomain
有損編輯使問題幾乎無法理解。 – Xan