如果(一组条件)做这个,如果(一组条件)做这个,如果(一组条件)做这个.什么
If (set of conditions) do this, if (set of conditions) do this, if (set of conditions) do this. What?
我正在建立一个天气网站,我使用Wunderground的API。在AJAX XML转储中,"icon"的值似乎是可行的。此响应将动态更改页面上的CSS。我有多个状态的页面,我想可能的,但我似乎不能让他们工作。它似乎在第一个"if"语句后停止。我需要它来检查是否wu_icon ==某些条件,如果不是,移动到下一个,看看是否wu_icon ==下一组条件。
网址在这里
任何帮助都将非常感激。
function get_weather(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
wu_query = latitude + ',' + longitude;
//Weather underground request URL format.
wu_url = wu_base_url + '/' + wu_api_key + '/' + wu_features + '/q/' + wu_query + '.json';
console.log('URL Query: ' + wu_url);
$.ajax({
url: wu_url,
dataType: "jsonp",
success: function(parsed_json) {
console.log(parsed_json);
var location = parsed_json['location']['city'];
var wuurl = parsed_json['location']['wuiurl'];
//simple forecast day 1.
var wu = parsed_json['current_observation'];
var wu_temp_f = wu['temp_f'];
var wu_high_temp = wu['high'];
var wu_low_temp = wu['low'];
var wu_icon = wu['icon'];
$('#location').html(location);
$('#temp').html(wu_temp_f + '°F');
if (wu_icon == 'partlycloudy' || 'partlysunny' || 'unkown'){
document.getElementById('rainclouds').style.display = 'none';
document.getElementById('topclouds').style.display = 'block';
document.getElementById('bottomclouds').style.display = 'block';
document.getElementById('canvas').style.display = 'none';
document.getElementById('snow').style.display = 'none';
window.alert("1");
}
else if (wu_icon == 'rain' || 'chancerain' || 'chancetstorms' || 'tstorms'){
document.getElementById('rainclouds').style.display = 'block';
document.getElementById('topclouds').style.display = 'none';
document.getElementById('bottomclouds').style.display = 'none';
document.getElementById('canvas').style.display = 'block';
document.getElementById('snow').style.display = 'none';
window.alert("2");
}
else if (wu_icon == 'flurries' || 'snow' || 'chanceflurries' || 'chancesnow'){
document.getElementById('rainclouds').style.display = 'block';
document.getElementById('topclouds').style.display = 'none';
document.getElementById('bottomclouds').style.display = 'none';
document.getElementById('canvas').style.display = 'none';
document.getElementById('snow').style.display = 'block';
window.alert("3");
}
else if (wu_icon == 'clear' || 'mostlysunny' || 'sunny'){
document.getElementById('rainclouds').style.display = 'none';
document.getElementById('topclouds').style.display = 'block';
document.getElementById('bottomclouds').style.display = 'none';
document.getElementById('canvas').style.display = 'none';
document.getElementById('snow').style.display = 'none';
window.alert("4")
}
else if (wu_icon == 'chancesleet' || 'sleet'){
document.getElementById('rainclouds').style.display = 'block';
document.getElementById('topclouds').style.display = 'none';
document.getElementById('bottomclouds').style.display = 'none';
document.getElementById('canvas').style.display = 'block';
document.getElementById('snow').style.display = 'block';
window.alert("5");
}
else if (wu_icon == 'cloudy' || 'mostlycloudy' || 'fog' || 'hazy'){
document.getElementById('rainclouds').style.display = 'block';
document.getElementById('topclouds').style.display = 'none';
document.getElementById('bottomclouds').style.display = 'none';
document.getElementById('canvas').style.display = 'none';
document.getElementById('snow').style.display = 'none';
window.alert("6");
}
}
你的if语句应该像
if (wu_icon == 'partlycloudy' || wu_icon == 'partlysunny' || wu_icon == 'unkown')
的缩写形式是
if (["partlycloudy","partlysunny","unkown"].indexOf(wu_icon) != -1)
相关文章:
- fluxxor向一个flux实例添加一组以上的操作
- 我们怎样才能将内含子J用于一组特定的元素
- 使用linq.js按当前日期订购一组momentjs日期
- 正则表达式,从一组关键字中获取奇数
- 创建一组元素JointJS
- 如何在javascript中获取一组复选框值
- 一组(共组..)
- 使用JS将页面中的每个字母设置为随机颜色.为什么在页面的每个打开标记之前总是有一组额外的span标记
- 在一组复选框中,一次只允许选择一个
- 为什么在fabricjs中可选择的不适用于一组圆
- 如何在不刷新页面的情况下每次单击一组选项卡时刷新视图内容窗格
- 从一组具有相同起始和结束的所有段落的段落中提取包含特定字符串的段落
- 简单的Javascript文本编辑器或一组函数
- 基于日期范围的一组日期范围内的天数
- 处理对象数组并将它们以 4 个为一组进行分配
- 如何在 Javascript 中用一组字符拆分子字符串上的字符串
- 使一组对象与 jQuery 一起拖动
- 使用第 n 个类型设置一组八个元素的样式
- 如果(一组条件)做这个,如果(一组条件)做这个,如果(一组条件)做这个.什么
- 有没有更简洁的方法在js中编写一组基于时间的条件?