本文介紹了在傳單彈出窗口中顯示圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試使用 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)
應該適合你.
這篇關于在傳單彈出窗口中顯示圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!