javascript - 如何检查用户是否选择了一个属性
问题描述
解决方案
我想你在找这个
$.getJSON("https://restcountries.eu/rest/v2/all", function(countryData) {
var countryCodes = countryData.map(item => `<option value="${item.alpha2Code}">${item.name}</option>`);
$("#country-select")
.html('<option value="">Country</option>')
.append(countryCodes.join(""));
})
$("#country-select").on("change", function() {
console.log(this.value)
})
$("#weather-button").click(function() {
$(".weather-img").html("");
$(".weather-type").html("");
$(".weather-temp").html("");
var city = $("input[name=city-box]").val();
var region = $("#country-select").val() || "whatever is default country code";
$.getJSON("https://api.openweathermap.org/data/2.5/weather?q=" + city + region + "&units=metric&myapikey", function(data) {
console.log(data);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="country-select"></select>
推荐阅读
- kubernetes - 服务“kube-dns”无效:spec.clusterIP:无效值:“10.10.0.10”:字段不可变
- karate - 后台操作失败时将场景测试标记为已跳过
- react-native - 将通知深度链接延迟到完全加载 react-native expo 应用程序之后
- node.js - 将 TFS2017 任务更新到最新版本
- python - 无法在python中将数据发送到特定的websocket客户端
- angular - Ionic4 ion-slide,循环配置打开时不工作的属性
- javascript - 在反应中渲染地图的大小
- javascript - 如何通过钩子更新对象状态
- python - Django 的多种用户类型和角色
- java - 将随机字符数设置为数组