php开发之javascript第一个程序

时间:2022-10-21 20:03:05

关于基本的概念在这里就不说了,我按照书上的代码敲出了自己的第一个javasript程序,也就是自己的hello world 。对自己是一个很大的鼓励。下面我把代码贴出来和大家一块学习。
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>

运行结果如下:

php开发之javascript第一个程序