我提供了以下jsfiddle:
https://jsfiddle.net/joegerofsky/huo9r59p/
这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
<p>
City: <input id='city' value='Toronto'></input>
<br>
<button id='submit'>Submit</button>
</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="../p5.min.js"></script>
<script src="../addons/p5.dom.min.js"></script>
<script src="../addons/p5.sound.min.js"></script>
<script src="weather.js"></script>
</body>
下面是我的js:
var api_key = "&APPID=c0aa3c8995df1b0dd97032d0072333b3";
var api = "http://api.openweathermap.org/data/2.5/forecast?q=";
var city = "Toronto";
var units = "&units=metric"
$( "#submit" ).click(function() {
input = select('#city');
$(function(){
var url = api + input.value() + api_key + units;
$.getJSON(url, function(wd){
console.log('got the data', wd);
})
})
});我的控制台在第11行显示"select is not defined“。我实际上是在尝试使用jQuery而不仅仅是p5js从https://www.youtube.com/watch?v=4UoUqnjUC2c构建天气应用程序。有人能帮上忙吗?
发布于 2018-01-22 11:22:55
select()函数是p5.js的属性。如果你想使用jquery而不是p5,你应该使用jquery选择器,它是$('#id')的,在你的例子中是$('#city')。
查看购买的库的文档:
问候!!
https://stackoverflow.com/questions/48374008
复制相似问题