我正在處理的小天氣預報應用程序。我一直在試圖將溫度從攝氏溫度變爲華氏溫度,但是我所做的所有更改都不會改變數值或完全消除該線。我想學習使用數據屬性,如果有可能訪問和更改數據值
$(document).ready(function(){
var long;
var lat;
$.getJSON("https://crossorigin.me/http://ip-api.com/json", function(data2){ //access RESTFUL geo location API & set lattitude.longitude
lat=data2.lat;
long=data2.lon;
var api = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&appid=de61ccfbde0405f57d64dbb53323fccf&units=metric";
//Access weather API
$.getJSON(api, function(data){
var iconCode = data.weather[0].icon; //get Icon from API related to current weather conditions
var iconUrl = "http://openweathermap.org/img/w/"+iconCode+".png";
var tempCel = data.main.temp;
$(".heading").append("<h2>"+data.name+","+data.sys.country+"</h2>");
$(".message").append("<h4 id='tempData' data-temp='" + tempCel + "'>Current Temperature: "+tempCel+"℃</h4>");
$(".message").append("<h4>Conditions: "+data.weather[0].main+"</h4>");
// $("#reveal").on('click', function(){ //click button
// data.main.tempData //on click convert temperature to farenheight
// });
$(".message").append("<img id='conditions' src="+iconUrl+">");
$("#tempData").hover(function(){
$("#tempData").fadeToggle('slow', function(){
});
});
console.log(data);
});
});
//$("#reveal").on("click", function(){
//});
});
只需使用 –