2016-05-06 55 views
0

我嘗試使用comments mark設置輸入類型的代碼。 我想獲得輸入類型,所以我可以添加一個specific GMT如何在html中使用javascript在input =「time」中放置時間

<html> 
<head> 
<script language="JavaScript"> 

function calcTime(city, offset) { 

    d = new Date(); 
    utc = d.getTime() + (d.getTimezoneOffset() * 60000); 
    nd = new Date(utc + (3600000*offset)); 
    document.write("\n\t\n"); 
    return "<br>"+"The local time in " + city + " is " + nd.toLocaleString()+ "<br>" ; 
} 

// get Singapore time 
//document.write(calcTime('Singapore', '+8')); 
//document.getElementById("tim").value = "(calcTime('Singapore', '+8'))"; 
//document.write("tim").value = (calcTime('Singapore', '+8')); 
// get London time 
//document.write("tim".value(calcTime('London', '+1'))); 
// I TRIES THE CODES^BUT IT IS NOT 
document.write(calcTime('Moscow', '+3')); 

</script> 
</head> 
<body> 

<input type="time" name="tim" id="tim" value =""> 
</body> 
</html> 

回答

0

您可以嘗試.value與選擇器。如下:

document.getElementById("tim").value = "22:53:05"; 

更新:

入住這Fiddle演示

+0

我說像這樣 的document.getElementById( 「蒂姆」)值=「22時53分05秒「;但它尚未處於輸入類型 –

+0

請確保在'body'內有此腳本,並且'

相關問題