關于基本的概念在這里就不說了,我依照書上的代碼敲出了自己的第1個javasript程序,也就是自己的hello world 。對自己是1個很大的鼓勵。下面我把代碼貼出來和大家1塊學習。
index.php
<?php
header('Content-type:text/html');
include 'test.html';
?>
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<script type ="text/javascript">
function cubeme(incomingNum){
if(incomingNum ==1){
return "what are you doing ?";
}else{
return Math.pow(incomingNum,3);
}
}
</script>
<title>JavaScript Test</title>
</head>
<body>
<script type ="text/javascript">
var theNum =2;
var finalNum =cubeme(theNum);
if(isNaN(finalNum)){
alert("You should know that 1 to any power is 1.");
}
else{
alert("when cubed ," + theNum + "is" + finalNum);
}
</script>
</body>
</html>
運行結果以下: