本文介紹了在傳單彈出窗口中顯示圖像的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試使用 wunderground 的 API、Leaflet 和 Cloudmade 讓天氣圖標(biāo)顯示在地圖標(biāo)記中.我已經(jīng)顯示了文本和帶有圖標(biāo)圖像的變量,但我不確定如何顯示它.這是我的代碼:
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();
有什么建議嗎?
推薦答案
標(biāo)記的 bindPopup 方法只是將 HTML 內(nèi)容作為一個字符串,所以你也需要用引號將你的標(biāo)簽括起來 - 比如
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)
應(yīng)該適合你.
這篇關(guān)于在傳單彈出窗口中顯示圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!