2013-11-26 133 views
0

我使用openweathermap为我的网站构建了天气小部件。 JS & HTML是 -
JS - >使用openweathermap显示天气数据

$(function() { 

     $('.weather-temperature').openWeather({ 
      city: 'Dhaka, BD', 
      descriptionTarget: '.weather-description', 
      windSpeedTarget: '.weather-wind-speed', 
      minTemperatureTarget: '.weather-min-temperature', 
      maxTemperatureTarget: '.weather-max-temperature', 
      humidityTarget: '.weather-humidity', 
      sunriseTarget: '.weather-sunrise', 
      sunsetTarget: '.weather-sunset', 
      placeTarget: '.weather-place', 
      iconTarget: '.weather-icon', 
      customIcons: 'images/icons/weather/', 
      success: function() { 

       //show weather 
       $('.weather-wrapper').show(); 

      }, 
      error: function(message) { 

       console.log(message); 

      } 
     }); 

    }); 

HTML - >/*

        <div class="weather-wrapper hide"> 
       <select id='list'> 
         <option value='1'>Dhaka</option> 
         <option value='2'>Pabna</option> 
       </select> 

       <img src="" class="weather-icon" alt="Weather Icon" /> 

       <p><strong>Place</strong> 
       <br /><span class="weather-place"></span></p> 

       <p><strong>Temperature</strong> 
       <br /><span class="weather-temperature"></span> (<span class="weather-min-temperature"></span> - <span class="weather-max-temperature"></span>)</p> 

       <p><strong>Description</strong> 
       <br /><span class="weather-description capitalize"></span></p> 

       <p><strong>Humidity</strong> 
       <br /><span class="weather-humidity"></span></p> 

       <p><strong>Wind speed</strong> 
       <br /><span class="weather-wind-speed"></span></p> 

       <p><strong>Sunrise</strong> 
       <br /><span class="weather-sunrise"></span></p> 

       <p><strong>Sunset</strong> 
       <br /><span class="weather-sunset"></span></p> 

      </div>  */ 

//

没有它正常工作了“达卡任何 '选择' 选项'城市。我想使用选择选项更改城市名称并显示已更改的天气数据。如何使用jquery.change()。 Plz帮助我。

+0

你需要触发改变/点击选择元素的您js函数,并通过所选择的选项的值。 ('(this).val()==='1'){ $(()){('#list')。change(function(){ if($(this).val()==='1( – sideroxylon

+0

)//我已经做了这个但不工作// $ '.weather-temperature')。openWeather({ city:'Dhaka,BD', ................ customIcons:'images/icons/weather /', 成功:函数(){ //显示天气 $( '天气包装。')示出了(); 。}, 错误:函数(消息){ 的console.log(消息); } }); } }); –

回答

0

试试这个: HTML

<select id='list'> 
        <option value='Dhaka'>Dhaka</option> 
        <option value='Pabna'>Pabna</option> 
      </select> 

JS

var loc; 
$('#list').change(function() { 
loc = $('#list').val(); 
    $('.weather-temperature').openWeather({ 
    city: "' + loc + '", 
    //etc. 
+0

这段代码看起来很完美。但它不工作。并且它在咒骂我,我不知道为什么它不工作。你有另一种解决方案吗 –