<!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>
谢谢

解决方案 »

  1.   


    // this稍微拗口点的解释就是 引用包含它的函数做为某个对象的方法被调用时的那个对象
    这里包含this的函数就是item.onclick而调用这个函数的对象就是window 所以this就指向
    这个Window对象.用fun.call(item);就将this指针指向item了
      

  2.   


    <!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>
      

  3.   

    在ie6下面这种写法报error
    alert(send.location.href)
      

  4.   

    指定scope即可<!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 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>
      

  5.   

     <input type="button" value="测试" onclick="Login(this,1,2,3)">在这句话里this才代表input
    ,但是Login是window下的,如果你取出来再调用(这时onclick指向Login这个方法,跟input没有关系 了,所以this指向window)Login已经不属于input了),而是window了,所以要使用call
      

  6.   

    send.location.href这句有问题了
    如果你换成 send.value看看是不是你想要的结果
      

  7.   

    你html中的那句话相当于
    <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);}这样
      

  8.   

    问题在这fun.call(); 当前执行fun.call(); 相当于是调用 Login 方法 传递的参数是 this,1,2,3而 fun.call();  所在环境的 this 指向是 window而不是 <input button 因为 只有在 <input type="button" value="测试" onclick="Login(this,1,2,3)">这个时候 使用this 才表示 buttonfun.call(item);  是使用了 call 的第一个参数  “将被用作当前对象的对象”也就是用item 代替了当前对象(window) ,所以可以达到效果