我有一个界面导入了一个自己写的KeyCode.js 然后在界面调用JS里面的方法 具体代码如下
我想在一个按钮的onclick事件上调用JS里面的create方法 我想要把当前这个按钮对象同时传到js中的create方法和test1方法里面 我是这样写的 onclick="KeyCode.create(this,'test1(this)','39','39+ctrl');" 但是传过去后只有第一个this是当前这个按钮对象 而test1里面的this却变成了js里面的KeyObj(代理是KeyCode)对象 并且我这个test1里面只能传一个参数 那就是this如果传其它参数的话就会报错 如我的第二个按钮像这样定义就会报错onclick="KeyCode.create(this,'test2(this,"aa")','39','39+ctrl');" 请我各位高手我该怎么解决这个问题 并且能把当前按钮对象同时传到JS中的create方法和界面的test方法 而且我希望test方法里面还可以传其它参数?<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><script type="text/javascript" src="js/KeyCode.js"></script>
<script type="text/javascript">
function test1(obj){
alert(obj);
}
function test1(obj,a){
alert(obj);
alert(a);}
</script>
</head>
<body>
<input id="btn1" type="button" onclick="KeyCode.create(this,'test1(this)','39','39+ctrl');" value="右方向键"><br> <input id="btn2" type="button" onclick="KeyCode.create(this,'test2(this,"aa")','39','39+ctrl');" value="右方向键"><br>
</body>
</html>
function KeyObj(){
this.create=KeyObj_create;
}
function KeyObj_create(obj,method,alone,dbstr){
eval(method);
}
var KeyCode = new KeyObj();
我想在一个按钮的onclick事件上调用JS里面的create方法 我想要把当前这个按钮对象同时传到js中的create方法和test1方法里面 我是这样写的 onclick="KeyCode.create(this,'test1(this)','39','39+ctrl');" 但是传过去后只有第一个this是当前这个按钮对象 而test1里面的this却变成了js里面的KeyObj(代理是KeyCode)对象 并且我这个test1里面只能传一个参数 那就是this如果传其它参数的话就会报错 如我的第二个按钮像这样定义就会报错onclick="KeyCode.create(this,'test2(this,"aa")','39','39+ctrl');" 请我各位高手我该怎么解决这个问题 并且能把当前按钮对象同时传到JS中的create方法和界面的test方法 而且我希望test方法里面还可以传其它参数?<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><script type="text/javascript" src="js/KeyCode.js"></script>
<script type="text/javascript">
function test1(obj){
alert(obj);
}
function test1(obj,a){
alert(obj);
alert(a);}
</script>
</head>
<body>
<input id="btn1" type="button" onclick="KeyCode.create(this,'test1(this)','39','39+ctrl');" value="右方向键"><br> <input id="btn2" type="button" onclick="KeyCode.create(this,'test2(this,"aa")','39','39+ctrl');" value="右方向键"><br>
</body>
</html>
function KeyObj(){
this.create=KeyObj_create;
}
function KeyObj_create(obj,method,alone,dbstr){
eval(method);
}
var KeyCode = new KeyObj();
<html>
<script type="text/javascript">
function KeyObj(){
this.create=KeyObj_create;
}
function KeyObj_create(obj,method,alone,dbstr){
method;
}
var KeyCode = new KeyObj();
</script>
<script type="text/javascript">
function test1(obj){
alert(obj.value);
}
function test2(obj,a){
alert(obj);
alert(a);}
</script>
</head>
<body>
<input id="btn1" type="button" onclick="KeyCode.create(this,test1(this),'39','39+ctrl');" value="右方向键"><br> <input id="btn2" type="button" onclick="KeyCode.create(this,test2(this,'aa'),'39','39+ctrl');" value="右方向键"><br>
</body>
</html>
咋找不到对象了?你测试了吗function test1(obj){
alert(obj.tagName);
}