【问题标题】:How do you manipulate the value of a variable through the use of an input text field and submit button如何通过使用输入文本字段和提交按钮来操作变量的值
【发布时间】:2019-07-07 02:20:28
【问题描述】:

我目前正在尝试设置天气 API,但在更改城市时遇到了麻烦。我有我的 url 设置方式,我可以操纵城市将变量传递到地址。我想不通的是如何在用户可以使用输入和提交按钮更改变量的位置获取它。

var city = 'calera';

('GET', https://api.openweathermap.org/data/2.5/weather?q= + 城市 +&appid=a34f9192fd6fa82116ba2227981b319a&units=imperial);

【问题讨论】:

    标签: javascript html weather-api


    【解决方案1】:

    您可以在this guide 之后获取输入字段的值。所以它看起来像

    city = document.getElementById("myText").value
    

    在您的submit button handler 以及您的获取请求中。当然你需要事先设置相应的html元素。

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 2021-09-10
      • 2014-03-27
      • 1970-01-01
      相关资源
      最近更新 更多