我显示昨天的日期与此帮助下面的代码,这一切工作正常,但我的要求是,我需要显示变量昨天作为全球性的,因为我要为其他目的使用还如何在这种情况下使全局变量?
变量<!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使变量全局” - 这是误导和不正确的。 –