Javascript DOM没有呈现它应该呈现的内容
我有这个JS:Javascript DOM没有呈现它应该呈现的内容,javascript,jquery,Javascript,Jquery,我有这个JS: function climat(code, isday, hour){ weather = {'113': (isday == "yes" && hour < 4) ? '<i class="sunn"></i>' : '<i class="moonn"></i>' } return weather[code] }; function Meteo(d) { for (h = 1;
function climat(code, isday, hour){
weather = {'113': (isday == "yes" && hour < 4) ? '<i class="sunn"></i>' : '<i class="moonn"></i>' }
return weather[code]
};
function Meteo(d) {
for (h = 1; h < 4; h++) {
alert(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime, h));
$("#meteo"+h).html(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime), h)
}
};
这是一个屏幕截图,名为sunn
,但它呈现moonn
:
这一行:
$("#meteo"+h).html(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime), h);
应该是:
$("#meteo"+h).html(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime, h));
您将
h
作为.html()
的第二个参数,而不是climat()
的第三个参数。因此,您在发出警报时调用climat()
的方式与添加HTML时不同。在第二次调用climat
时,您只传递了一个参数,在第一次调用中传递了两个参数。在第二次调用中,h
被传递给html
函数,因为该函数接受零个或一个参数,我假设这是错误
for (h = 1; h < 4; h++) {
alert(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime, h));
$("#meteo"+h).html(
climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime),
h)
}
(h=1;h<4;h++)的{
警报(气候(气象[d]。每小时[h]。天气代码,气象[d]。每小时[h]。isdaytime,h));
$(“#meteo”+h).html(
气候(气象[d]。每小时[h]。天气代码,气象[d]。每小时[h]。isdaytime),
h)
}
@DavidThomas抱歉,我粘贴了一个额外的{
,它来自主函数函数Meteo(d){
简单的输入错误:h
参数不在climat()的参数列表中
function call@Barmar awww!我应该更改我的IDE首选项:D谢谢!你刚刚救了我一个晚上!你能把它写成答案让我验证一下吗?凌晨2点不戴眼镜编程不是个好主意:D谢谢^ ^问题是打字错误,一个简单的括号让我发疯了:D谢谢
for (h = 1; h < 4; h++) {
alert(climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime, h));
$("#meteo"+h).html(
climat(meteo[d].hourly[h].weatherCode, meteo[d].hourly[h].isdaytime),
h)
}