我顯示昨天的日期與此幫助下面的代碼,這一切工作正常,但我的要求是,我需要顯示變量昨天作爲全球性的,因爲我要爲其他目的使用還如何在這種情況下使全局變量?
變量<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
var d = new Date();
d.setDate(d.getDate() - 1);
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var yesterday = curr_year + "-" + curr_month + "-" + curr_date;
alert('The value after modifications is'+yesterday)
}
</script>
</head>
<body>
<p id="demo">New Modifications FOR Click Button to Display Yesterday Date</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
請告訴我如何在這個例子中顯示變量昨天作爲全局,在此先感謝。
「通過讓前綴var使變量全局」 - 這是誤導和不正確的。 –