【发布时间】:2019-04-13 05:54:48
【问题描述】:
我需要这样做,以便当在框中输入邮政编码并单击提交按钮时,城市名称会显示在其下方。当我输入邮政编码后单击按钮时,城市名称不显示。它说错误是 wallOfText 不是一个函数,但我不知道如何修复它。任何帮助,将不胜感激!!这是代码:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>
Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
<button onclick="weatherFunction()">Submit</button>
<p id="result"></p>
<script>
function weatherFunction() {
var zip = document.getElementById("zipBox").value;
jQuery(document).ready(function ($) {
$.ajax({
url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
dataType: "jsonp",
success: function (wallOfText) {
city = wallOfText("name");
if (zip != null) {
document.getElementById("result").innerHTML = wallOfText;
}
}
});
});
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript jquery weather openweathermap