我正在尝试创建动态src,但无法完成。 我认为我缺少了一些东西,该东西会将.png文件收集到src位置的项目中。
查看时,信息为“ SRC = UNKNOWN” 有人有主意吗?
这是我的代码。
function updateweather(){
var url = "http://192.168.178.29:8080/json.htm?type=devices&rid=96";
var forecast
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.responseText);
forecast = myArr.result[0].ForecastStr;
console.log("Forecast is "+forecast+".")
// myFunction(myArr);
if (forecast == "Partly Cloudy") {
document.getElementById("weatherindicator").src = "weatherback-partlycloudy.png";
}
if (forecast == "Sunny") {
document.getElementById("weatherindicator").src = "weatherback-sunny.png";
}
if (forecast == "Rain") {
document.getElementById("weatherindicator").src = "weatherback-rain.png";
}
if (forecast == "Fog") {
document.getElementById("weatherindicator").src = "weatherback-fog.png";
}
if (forecast == "Snow") {
document.getElementById("weatherindicator").src = "weatherback-snow.png";
}
if (forecast == "Cloudy") {
document.getElementById("weatherindicator").src = "weatherback-cloudy.png";
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
setTimeout(updateweather,6000);
}
//-->
</script>
<body>
<div id="weatherdisplay" align="left" class="weatherback"><img id="weatherindicator" src="" /></div>
</body>
</html>