2015-10-17 66 views
0

我有這樣的代碼:

$('#location').html(location); 
$('#temperature').append(temperature); 
$('#temperature').attr("value", temperature); 
$('#weather').html(weather); 
$('#summary').html(summary); 
$('#hourly').html(hourly); 

我想要做的描述是HTML格式的每一個字顯示。像這樣$('#hourly').html(hourly) + 'next 24 hours' 但是那樣做的時候不會顯示下24小時描述。

回答

0

如果你想添加一些額外的文本,則需要使用相同的html功能添加:

$('#hourly').html(hourly + 'next 24 hours'); 
+0

他的工作感謝:) –

0

好了,所以這樣的:$('#location').html(location);查找一個名爲「位置」,所以它可以把變量它的內容在一個具有id="location"屬性的HTML元素中。

如果您鍵入如下內容:$('#location').html('location');字符串「location」將被插入到具有「location」id的元素中。

您可以組合任意數量的變量,字符串和函數作爲參數執行:$('#location').html('Current Location: ' + location);(假設「位置」變量包含當前位置的數據)。

如果你想顯示當前時間,有關於Date()的文章;功能,可以幫助你做到這一點:Current time formatting with Javascript

+0

非常感謝你 –