gpt4 book ai didi

javascript - 分配给 onclick() 时未定义的函数

转载 作者:行者123 更新时间:2023-12-03 03:36:59 26 4
gpt4 key购买 nike

我无法弄清楚为什么控制台日志中出现错误,告诉我函数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>

最佳答案

删除;之前 .appendTo( "body")

关于javascript - 分配给 onclick() 时未定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45811109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com