console
var globalVariable1=0;
function test1(){
var localVariable1=2;
document.write(globalVariable1+"<br/>");
document.write(localVariable1+"<br/>");
}
document.write("<br/>"+globalVariable2+"<br/>");
test1();
var globalVariable2=1;
function test2(){
var localVariable2=3;
}
test2();
document.write(globalVariable1+"<br/>");
document.write("=================================="+"<br/>");
function addSum(a, b){
var sum = a + b;
return sum;
}
var n = addSum(4,6) + 100;
document.write(n+"<br/>");
document.write("=================================="+"<br/>");
function RYear(year) {
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
return year + "年是闰年~";
}
else{
return year + "年不是闰年~";
}
}
document.write(RYear(2000)+"<br/>");
document.write(RYear(2001)+"<br/>");
document.write(RYear(2020)+"<br/>");
document.write("=================================="+"<br/>");
function getMax(n1,n2,n3,n4) {
var maxNum;
maxNum = (n1 > n2) ? n1 : n2;
maxNum = (maxNum > n3) ? maxNum : n3;
maxNum = (maxNum > n4) ? maxNum : n4;
return maxNum;
}
document.write("5个数中的最大值为:" + getMax(57,36,89,78));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>直接调用</title>
<script>
function gettest1()
{
document.write("早上好~"+"<br/>");
}
gettest1();
function GoodMes(){
alert("嗯嗯嗯下午好");
}
</script>
</head>
<body>
<a href="javascript:GoodMes()">下午好呀~</a>
</body>
</html>