我有這個簡單的Java腳本代碼來顯示日期。 我想從js中獲取結果,並在文檔中的特定html中顯示它們。例; div,p,h3等 如果我把腳本放在標籤中,它會覆蓋我現有的html頁面。 如何在html頁面中的特定標籤中顯示日期?在特定的html標記中顯示與JavaScript的日期
<script language="JavaScript">
<!--
var current_date = new Date ();
var month_names = new Array ();
month_names[month_names.length] = "January";
month_names[month_names.length] = "February";
month_names[month_names.length] = "March";
month_names[month_names.length] = "April";
month_names[month_names.length] = "May";
month_names[month_names.length] = "June";
month_names[month_names.length] = "July";
month_names[month_names.length] = "August";
month_names[month_names.length] = "September";
month_names[month_names.length] = "October";
month_names[month_names.length] = "November";
month_names[month_names.length] = "December";
document.write (month_names[current_date.getMonth()]);
document.write (" " + current_date.getDate());
document.write (" ");
document.write (" " + current_date.getFullYear());
// -->
</script>
申請宣告該陣列不必盡一切month_mans.length混亂。您可以簡單地做 var month_names = [「January」,「February」,「March」,「April」,「May」,「June」,「July」,「August」,「September」,「October」 ,「十一月」,「十二月」];' 並且您將得到完全相同的結果 – webdesserts 2012-03-15 19:35:04