我想用javascript來將時鐘追加到div的內部。這是我的代碼:Javascript:將文本追加到div中?
<script type="text/javascript">
//<![CDATA[
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}
var months = new makeArray('January','February','March','April','May',
'June','July','August','September','October','November','December');
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var timer = document.write(months[month]+ " " +day + ", " + year);
document.getElementById('time').appendChild(timer);
//]]></script>
<div id='time'></div>
但它不起作用。幫我修復它。謝謝。
定義「不起作用」。 – Utkanos
工作正常http://jsfiddle.net/5Khyc/ –
複製粘貼錯誤(如有) –