我正在开发一个天气应用程序,并想使用回车键将城市名称提交到服务器。但是,出现了以下错误:
submit不是一个函数
我想解决这个问题,并且我想知道如何发送值到Express服务器以便在API调用中使用它。以下是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Weather APP</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<input id="City" placeholder="EnterCity" onclick="u()" action="/" method="post">
</body>
<script>
function u(){
document.getElementById("City").addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
var x = document.getElementById("City");
x.submit();
return false;
}
});
}
</script>
</html>