函數(shù)基礎(chǔ) 函數(shù)的調(diào)用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js函數(shù)</title>
<script type="text/javascript">
function aa(){
alert('hello!');
}
/*
//直接調(diào)用
aa();
*/
</script>
</head>
<body>
<input type="button" name="" value="彈框" onclick="aa()" />
</body>
</html>
函數(shù)與解析
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>變量和函數(shù)預(yù)解析</title>
<script type="text/javascript">
/*變量預(yù)解析*/
/*alert(a);//只把變量a的聲明提前,賦值不提前,所以彈出undefined,表示它的值未定義
// alert(c);//報錯或衡,c沒有聲明,這是真正的未定義
var a = 123;
/*函數(shù)預(yù)解析*/
myalert();//彈出hello!
function myalert(){
alert('hello!');
}
</script>
</head>
<body>
</body>
</html>