按钮 btn1_click 未执行
Button btn1_click is not executing
btn1_click
没有运行。 Visual Studio 2017 年没有错误或警告。一定有一些简单的事情我没有做。我确信我的 api 网站是正确的。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>weatherjson</title>
<style>
body {
position: fixed;
top: 0px;
bottom: 100%;
height: 100%;
left: 0px;
right: 100%;
width: 100%;
background-color: green;
}
</style>
</head>
<body>
<script type="text/javascript">
function btn1_click() {
fetch('https://api.openweathermap.org/data/2.5/onecall?lat=40.79&lon=-81.347&exclude=minutely&appid=94d45728ae0f1341c6c5b0527162f90d').then(response => response.json()).then((obj) => {
TextArea1.value = obj;
});
}
</script>
<input id="Button1" type="button" value="get json" onclick="btn1_click()" />
<textarea id="TextArea1" rows="200" cols="200"></textarea>
</body>
</html>
你的按钮没有问题,但我想你想在文本区域显示数据,所以你必须写出你需要显示的属性,这应该是这样的
function btn1_click() {
fetch(
"https://api.openweathermap.org/data/2.5/onecall?lat=40.79&lon=-81.347&exclude=minutely&appid=94d45728ae0f1341c6c5b0527162f90d"
)
.then((response) => response.json())
.then((obj) => {
TextArea1.value = `${obj.lat} ${obj.lon} ${obj.timezone} ${obj.current.dt}`;
});
}
body {
position: fixed;
top: 0px;
bottom: 100%;
height: 100%;
left: 0px;
right: 100%;
width: 100%;
background-color: green;
}
<input id="Button1" type="button" value="get json" onclick="btn1_click()" />
<textarea id="TextArea1" rows="200" cols="200"></textarea>
查看哪些属性可用console.log(obj)
btn1_click
没有运行。 Visual Studio 2017 年没有错误或警告。一定有一些简单的事情我没有做。我确信我的 api 网站是正确的。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>weatherjson</title>
<style>
body {
position: fixed;
top: 0px;
bottom: 100%;
height: 100%;
left: 0px;
right: 100%;
width: 100%;
background-color: green;
}
</style>
</head>
<body>
<script type="text/javascript">
function btn1_click() {
fetch('https://api.openweathermap.org/data/2.5/onecall?lat=40.79&lon=-81.347&exclude=minutely&appid=94d45728ae0f1341c6c5b0527162f90d').then(response => response.json()).then((obj) => {
TextArea1.value = obj;
});
}
</script>
<input id="Button1" type="button" value="get json" onclick="btn1_click()" />
<textarea id="TextArea1" rows="200" cols="200"></textarea>
</body>
</html>
你的按钮没有问题,但我想你想在文本区域显示数据,所以你必须写出你需要显示的属性,这应该是这样的
function btn1_click() {
fetch(
"https://api.openweathermap.org/data/2.5/onecall?lat=40.79&lon=-81.347&exclude=minutely&appid=94d45728ae0f1341c6c5b0527162f90d"
)
.then((response) => response.json())
.then((obj) => {
TextArea1.value = `${obj.lat} ${obj.lon} ${obj.timezone} ${obj.current.dt}`;
});
}
body {
position: fixed;
top: 0px;
bottom: 100%;
height: 100%;
left: 0px;
right: 100%;
width: 100%;
background-color: green;
}
<input id="Button1" type="button" value="get json" onclick="btn1_click()" />
<textarea id="TextArea1" rows="200" cols="200"></textarea>
查看哪些属性可用console.log(obj)