<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>form.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form name="form1" action="test.html" method="post">
<input type="text" name="num1" />
<input type="text" name="num2" />
<input type="button" name="ok" value="保存1"/>
</form>
</body>
<script language="JavaScript">
//方法一使用普通方法
/*
* 普通方法定义函数:
*
* function 方法名(参数1,参数n){
*
* 方法体;
*
* }
*
*/
// function add(a,b){
// return a+b;
// }
//
// alert(add(3,4));
//方法二构造函数方式定义javascript函数
/*
* 构造函数方式定义函数:
*
* var 变量名 = new Function(参数1,参数n,方法体);
*
*/
// var add = new Function('a','b','return a+b;');
//
// alert(add(2,4));
//方法三使用函数直接量的方式定义函数
/*
* 直接量定义函数:
*
* var 变量名 = function(参数1,参数n){方法体}
*
*/
// var add = function(a,b){return a+b;}
//
// var add = function(a,b){
// return a+b;
// }
//
// alert(add(1,4));
</script>
</html>
JavaScript定义函数的方法
最新推荐文章于 2023-10-03 16:31:32 发布