Javascript 按钮-获取法兰克福API并使用API中的货币选项创建选择 javascript html api button Javascript 按钮-获取法兰克福API并使用API中的货币选项创建选择,javascript,html,api,button,fetch,Javascript,Html,Api,Button,Fetch,大家好,我的任务是创建获取API的按钮(法兰克福API)。同样,同一按钮必须创建一个带有的,其中的值和文本与API中的货币相同(选项编号与API中的货币相同)。f、 e: 我感谢任何提示/帮助。感谢您的时间。response.json()返回一个承诺,因此您必须使用异步。编写此提取请求的另一种方法是 fetch("https://api.frankfurter.app/latest") .then(async response => { if (!res 大家好,我的任务是创建获取API的按钮(法兰克福API)。同样,同一按钮必须创建一个带有的,其中的值和文本与API中的货币相同(选项编号与API中的货币相同)。f、 e: 我感谢任何提示/帮助。感谢您的时间。response.json()返回一个承诺,因此您必须使用异步。编写此提取请求的另一种方法是 fetch("https://api.frankfurter.app/latest") .then(async response => { if (!response.ok) { throw await response.json(); } return response.json(); }) .then(response => { waluta = response; }) .catch(err => { console.error(err); }) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>COCO</title> </head> <body> <button id="getCurrencies" onclick=Curr()>Click me</button> <script> </script> </body> </html> function Curr() { var waluta; fetch("https://api.frankfurter.app/latest") .then((response) => {(response.json()) .then((response) => {(waluta = response )}) }) var sel = document.createElement("select"); let op = document.createElement("option"); op.value = waluta.rates.euro document.body.appendChild(sel); } fetch("https://api.frankfurter.app/latest") .then(async response => { if (!response.ok) { throw await response.json(); } return response.json(); }) .then(response => { waluta = response; }) .catch(err => { console.error(err); })