<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="JS/jquery-1.3.2.1.min.js"></script>
<script type="text/javascript">
function Login(send, x, y, z)
{
alert(x);
alert(y);
alert(z);
alert(send.location.href)
//我发现了1,2,3值过来对应的x,y,z是没有变的
//但为什么这个this传过来就由原来的input变成了window呢?
//谢谢
}
</script>
<script type="text/javascript">
$(function()
{
var item = $(":input[type='button']").get(0);
var fun = item.onclick;
item.onclick = function()
{
alert("ABC");
fun.call();
};
});
</script>
</head>
<body>
<input type="button" value="测试" onclick="Login(this,1,2,3)">
</body>
</html>
谢谢
// this稍微拗口点的解释就是 引用包含它的函数做为某个对象的方法被调用时的那个对象
这里包含this的函数就是item.onclick而调用这个函数的对象就是window 所以this就指向
这个Window对象.用fun.call(item);就将this指针指向item了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="JS/jquery-1.3.2.1.min.js"></script>
<script type="text/javascript">
function Login(send, x, y, z)
{
alert(x);
alert(y);
alert(z);
alert(send.type);
alert(send.location.href)
//我发现了1,2,3值过来对应的x,y,z是没有变的
//但为什么这个this传过来就由原来的input变成了window呢?
//谢谢
}
</script>
<script type="text/javascript">
$(function()
{
var item = $(":input[type='button']").get(0);
var fun = item.onclick;
item.onclick = function()
{
alert("ABC");
fun.call();
};
});
</script>
</head>
<body>
<input type="button" value="测试" onclick="Login(this,1,2,3)">
</body>
</html>
alert(send.location.href)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.Microsoft.com/ajax/jQuery/jquery-1.3.2.min.js" type="text/javascript"> </script>
<script type="text/javascript">
function Login(send, x, y, z)
{
alert(x);
alert(y);
alert(z);
alert(send.value)
}
</script>
<script type="text/javascript">
$(function()
{
var item = $(":input[type='button']").get(0);
var fun = item.onclick;
item.onclick = function()
{
fun.call(item);
};
});
</script>
</head>
<body>
<input type="button" value="测试" onclick="Login(this,1,2,3)">
</body>
</html>
,但是Login是window下的,如果你取出来再调用(这时onclick指向Login这个方法,跟input没有关系 了,所以this指向window)Login已经不属于input了),而是window了,所以要使用call
如果你换成 send.value看看是不是你想要的结果
<input type="text" onclick="function(){Login(this,x,y,z)}"/>
而这里function(){Login(this,x,y,z)}只有在input中this才代表这个input
而且这个匿名方法是全局的,所以下面的this表示windowvar fun=function(){Login(this,x,y,z);}这样