【发布时间】:2015-03-20 14:43:55
【问题描述】:
以下代码工作正常,但我试图让它从 html 表单接收输入以从表单中选择任何位置。请参阅: text='chicago,il' 我希望它接收变量 text='location'
<script>
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
alert(wind.chill);
};
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
我的一些尝试:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script>
function getLocation() {
var city = document.getElementById("city").value;
var country = document.getElementById("country").value;
var location = city + "," + country;
//alert(location);
}
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
document.write(wind.chill)
alert(wind.chill);
};
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='location')&format=json&callback=callbackFunction"></script>
</head>
<body>
<input type="text" id="city">
<input type="text" id="country"
<button onclick="getLocation()">Get Weather</button>
</body>
</html>
我也尝试过其他方法,但即使我直接为 var location 分配一个字符串,例如 location="new york, ny" 或 "\'new york,ny\'" 等,它也不会返回一个值。请帮忙,谢谢。
【问题讨论】:
-
您的警报是否显示输入的位置?
标签: javascript variables src assign