【问题标题】:Add the possibility to select the city code添加选择城市代码的可能性
【发布时间】:2015-11-18 10:45:16
【问题描述】:
我想通过添加到此脚本的选择框来选择城市:
js:
$(document).ready(function() {
var example = $("#example").flatWeatherPlugin({
location: "london", //city and region *required
});
});
jsfiddle
【问题讨论】:
标签:
jquery
drop-down-menu
weather
【解决方案1】:
由于插件是专有的,您应该询问开发人员如何更新位置。可能有一个函数可以进行更改,然后您可以获取新数据。
始终可以删除保存插件的容器并将其附加到位置更改,但这并不是所谓的“好习惯”。
这是一个工作演示,但仍与开发人员交谈,应该有一种方法可以在不删除 HTML 元素的情况下制作它。
$(document).ready(function($) {
var example = $("#example").flatWeatherPlugin({
location: "london", //city and region *required
});
$('#list').on('change', function(){
var location = $(this).val();
//remove the previous instance of the element holding the weather plugin
$("#example").remove();
//Recreate the element and append it to the holder
$("#holder").append('<div id="example"></div>');
$("#example").flatWeatherPlugin({
location: location, //city and region *required
});
$("#example").flatWeatherPlugin('fetchWeather');
});
});
/* style the container however you please */
#example {
color:#fff;
background: #e74c3c;
padding: 5px;
margin: 30px auto;
width: 270px;
border-radius: 5px;
}
/* styling for this page only, ignore */
body {background: #95a5a6; font-family: b yekan,sans-serif; background: #ecf0f1; padding: 0; margin: 0;}
<link href="http://www.evanstoneworks.com/scripts/flatWeatherPlugin.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.evanstoneworks.com/scripts/jquery.flatWeatherPlugin.min.js"></script>
<div id="holder">
<div id="example"></div>
</div>
<select id="list">
<option value="london">london</option>
<option value="tokyo">tokyo</option>
<option value="paris">paris</option>
</select>
希望有帮助