在传单弹出窗口中显示图像

Show Image in Leaflet Popup(在传单弹出窗口中显示图像)
本文介绍了在传单弹出窗口中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 wunderground 的 API、Leaflet 和 Cloudmade 让天气图标显示在地图标记中.我已经显示了文本和带有图标图像的变量,但我不确定如何显示它.这是我的代码:

I'm trying to get the weather icon to show in a map marker using wunderground's api, Leaflet and Cloudmade. I've got the text showing and a variable with the icon image, but I'm not sure how to get it to show. Here's my code:

jQuery(document).ready(function($) {
    $.ajax({
          url: "http://api.wunderground.com/api/cd48ac26fb540679/conditions/q/pws:KCASANFR128.json",
          dataType: "jsonp",
          success: function(parsed_json) {
              var location = parsed_json['current_observation']['observation_location']['city'];
              var temp_f = parsed_json['current_observation']['temp_f'];
              var icon = parsed_json['current_observation']['icon_url'];
              marker1.bindPopup("Current temperature in " +location+ " is: " + temp_f).openPopup();
        }
    });
});

我试过这个没有成功:

marker1.bindPopup( <img src=icon> "Current temperature in " +location+ " is: " + temp_f).openPopup();

有什么建议吗?

推荐答案

标记的 bindPopup 方法只是将 HTML 内容作为一个字符串,所以你也需要用引号将你的标签括起来 - 比如

The marker's bindPopup method just takes HTML content as a string, so you'll need to surround your tags with quotes as well - something like

marker1.bindPopup( "<img src=" + icon_url + "/> Current temperature in " + location + " is: " + temp_f)

应该适合你.

这篇关于在传单弹出窗口中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)