第一种:
最基本的作为一个本本分分的函数声明使用。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Validate Page</title>
</head>
<script type="text/javascript">
function validate(abin){
var lee=function(parameter){
return 'hello,'+abin;
}(abin);
document.getElementById("spanId").innerHTML=lee;
}
</script>
<body>
<div id="divId" class="divs">
<input id="button" type="button" value="请猛击" onclick="validate('varyall')"/>
</div>
<br/>
<span id="spanId" class="spans"></span>
</body>
</html>
第二种:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Validate Page</title>
</head>
<script type="text/javascript">
var validate=function(abin){
var lee=function(parameter){
return 'hello,'+parameter;
}(abin);
document.getElementById("spanId").innerHTML=lee;
};
</script>
<body>
<div id="divId" class="divs">
<input id="button" type="button" value="请猛击" onclick="validate('varyall')"/>
</div>
<br/>
<span id="spanId" class="spans"></span>
</body>
</html>
第三种:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Validate Page</title>
</head>
<script type="text/javascript">
var validate=new Function("abin",
"var lee=function(parameter){return 'hello,'+parameter;}(abin);document.getElementById('spanId').innerHTML=lee;");
</script>
<body>
<div id="divId" class="divs">
<input id="button" type="button" value="请猛击" onclick="validate('who')"/>
</div>
<br/>
<span id="spanId" class="spans"></span>
</body>
</html>