我无法弄清楚为什么我在控制台日志中收到错误,告诉我函数weather()未定义。我研究了这个问题,我唯一能找到的就是关于词法范围的信息,但这似乎并没有解决我得到的错误。有人能告诉我我做错了吗?
这是我正在学习的测试应用程序,因此我可以解决工作中的应用程序的一些问题。
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" src="main.css">
<script type="text/javascript" scr="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<h1>The content of the document......</h1>
<input type="button" name="City: " value="London" onclick="weather()">
<script type="text/javascript">
var api_path = "http://api.openweathermap.org/data/2.5/weather?q="
var city = "London"
var api_key = "&appid=988bd58ad518778f5761aad912ed1ce8";
function weather (){
$.getJSON(api_path + city + api_key, function(data) {
var items = [];
$.each(data, function(key, value){
items.push( "<li id='" + key + "'>" + value + "</li>" );
});
.appendTo( "body" );
});
};
weather();
</script>
</body>
</html>
答案 0 :(得分:1)
删除;在.appendTo(“body”)之前