2012-01-31 19 views
0

嗨,我有這樣的jQuery的Ajax代碼如何插入此警報信息到一個div

<script type="text/javascript"> 
jQuery(document).ready(function($) { 
    $.ajax({ 
     url: "http://api.wunderground.com/api/10ea0e643a3d7699/geolookup/conditions/q/IA/Cedar_Rapids.json", 
     dataType: "jsonp", 
     success: function(parsed_json) { 
      var location = parsed_json['location']['city']; 
      var temp_f = parsed_json['current_observation']['temp_f']; 
      alert("Current temperature in "+location+" is: " + temp_f); 
     } 
    }); 
}); 
</script> 

,我想顯示警告的一樣

<div id="meteo"></div> 

回答

0

如果內容到一個div在體內內容文本使用:

$('#meteo').text("Current temperature in "+location+" is: " + temp_f); 

如果你的內容是HTML中使用:

$('#meteo').html("<span>Current temperature in "+location+" is: " + temp_f +"</span>"); 
0

如果你想在div包含內容純粹是文字,一個很好的選擇是:

$("#meteo").text("Current temperature in "+location+" is: " + temp_f) 

如果你想要把HTML內容的div裏面,這是更好的:

$("#meteo").html("Current temperature in "+location+" is: " + temp_f) 
1

您可以重寫警報函數,以進行任何調用以打開基於自定義DIV的彈出窗口,以便爲您的網站提供跨瀏覽器的一致彈出窗口。

window.alert = function() { 
    $('#meteo').html('your content'); 
    $('#meteo').show(); 
};