2013-04-29 70 views
0

我在互聯網上發現了一個javascript代碼,它可以顯示當地時間,但現在它不顯示在我的視圖中,誰可以幫助我?如何在用戶界面上顯示javascript

JavaScipt程式碼:

ourDate = new Date(); 
    result = document.write(ourDate.toLocaleString()); 
    $("#time").html(result); 

查看:

<td>Time:</td> 
    <td><span id="time"></span></td> 
+0

你有過的JavaScript加強檢查什麼結果評估呢?您可以使用Chrome中內置的開發者工具或Firefox中的Firebug。至少應該指出從哪裏開始尋找錯誤。 – Nomad101 2013-04-29 08:56:32

+0

您是否包含_JQuery_?工作[code](http://jsfiddle.net/BU5AQ/)。 – Vucko 2013-04-29 08:57:05

回答

2

如果你還沒有加入jQuery的話,請添加最新的jQuery的參考,您使用document.write()它總是您的變量寫入到您的視圖,以便初始化任何變量時不需要使用document.write()

替換此result = document.write(ourDate.toLocaleString());

與此:

result = ourDate.toLocaleString();

DEMO HERE

0

試試這個:

ourDate = new Date(); 
$("#time").html(ourDate.toLocaleString()); 
0

嘗試:

ourDate = new Date(); 
var result = ourDate .toLocaleString() ; 
$("#time").html(result); 
0

爲了縮短你的JavaScript,試試這個:

$("#time").html(new Date().toLocaleString()); 

看到它在這裏的行動:http://jsfiddle.net/x4dLf/1/

相關問題