<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'callBack.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
//测试身高是否达到标准
function testHeight(height,callback){
if(height<170){
alert("卧槽三级残废");
}else if(height>=170 && height<=180){
alert("男神身高");
var me=this || window;
var name="dandan";
var age="23";
//方法一
//callback("你是xiaoer吧","22");
//方法二
//callback.call(me,name,age);
//方法三
//arguments[1].call(me,name,age);
//方法四 调用callback的apply方法 ,但是this指向{name:'taolong'}的(第一个参数的内容),apply传递参数是以数组的形式传递
callback.apply({name:'taolong'},[name,age]);
}else{
alert("太高啦吧");
}
};
function startTest(){
var num=document.getElementById("score").value;
testHeight(num,function(msg,age){
alert("恭喜你一定是大受欢迎的男人:"+msg+" "+age+" "+this.name);
});
}
// (function(){
// testHeight(180,function(){
// alert("恭喜你一定是大受欢迎的男人");
// });
// })();
</script>
</head>
<body>
请输入你的身高<input type="text" id="score">
<input type="button" onClick="startTest()" value=" 看看结果">
</body>
</html>
js回调,apply,call 函数学习
最新推荐文章于 2022-07-13 16:14:52 发布