Jquery 如何将此警报信息插入div
嗨,我有这个jQuery ajax代码Jquery 如何将此警报信息插入div,jquery,ajax,weather-api,Jquery,Ajax,Weather Api,嗨,我有这个jQuery ajax代码 <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",
<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>
jQuery(文档).ready(函数($){
$.ajax({
url:“http://api.wunderground.com/api/10ea0e643a3d7699/geolookup/conditions/q/IA/Cedar_Rapids.json",
数据类型:“jsonp”,
成功:函数(已解析的_json){
var location=parsed_json['location']['city'];
var temp_f=parsed_json['current_observation']['temp_f'];
警报(“位置+”中的当前温度为:“+temp_f”);
}
});
});
我想把alert的内容显示在一个div中,就像
<div id="meteo"></div>
如果内容是文本,请使用:
$('#meteo').text("Current temperature in "+location+" is: " + temp_f );
如果您的内容是html,请使用:
$('#meteo').html("<span>Current temperature in "+location+" is: " + temp_f +"</span>");
$('#meteo').html(“位置+”中的当前温度为:“+temp#f+”);
如果要包含在div中的内容纯粹是文本,那么一个好的选择是:
$("#meteo").text("Current temperature in "+location+" is: " + temp_f)
如果要将HTML内容放入div中,最好:
$("#meteo").html("Current temperature in "+location+" is: " + temp_f)
您可以覆盖警报功能,以进行任何警报调用,打开一个自定义的基于DIV的弹出窗口,在浏览器之间提供一致的弹出窗口,并为您的站点提供自定义的感觉
window.alert = function() {
$('#meteo').html('your content');
$('#meteo').show();
};