为什么
<input type="submit" value="登录" onclick="Login(this)" />
这里的this为是全本身这个input而是window对像呢?
谢谢,那这里要传他本身要怎么写

解决方案 »

  1.   

    是啊我也奇怪
    以下是代码<!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" src="JS/YK-Validate/YK_Validate.js"></script>
        <script type="text/javascript" src="JS/Global.js"></script>
        <script type="text/javascript" src="JS/Active/CompanyUser.js"></script>
        <script type="text/javascript">
            $(function()
            {
                //用户名焦点
                $("#frmLogin [name=userName]").focus();
            });
        </script>
        <script type="text/javascript">        function Login(send)
            {
                alert(send.location.href);  //我这里alert出了我的网站,所以这里为window对像,我晕
                var userName = $("[name=userName]").val();
                var userPass = $("[name=userPass]").val();
                var result = CompanyUser.Login(userName, userPass, send);
                window.location.href = Global.Site;
            }
        </script>
    </head>
    <body>
        <form id="frmLogin">
        <table border="0">
            <tr>
                <td align="right">
                    用户名:
                </td>
                <td>
                    <input type="text" name="userName" value="" />
                    <label for="userName" lang="tip">
                    </label>
                </td>
            </tr>
            <tr>
                <td align="right">
                    密码:
                </td>
                <td>
                    <input type="password" name="userPass" value="" />
                    <label for="userPass" lang="tip">
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <input type="submit" value="登录" onclick="Login(this)" />
                </td>
            </tr>
        </table>
        </form>
    </body>
    </html>
      

  2.   

    哦,我知道是
    那是因为我在另一个地方把他更改了
    如:            //绑定执行优先
                //找出当前form中的提交按钮,
                var submits = $(settings.form).find("[type=submit]").not("[validatorGroup]");
                for (var i = 0; i <= submits.length - 1; i++)
                {
                    var item = submits[i];
                    //取得这个按钮的点击事件保存存来
                    var fun = item.onclick; //这个就是那个提交按钮,那我怎么把他原来的参数,再在这里赋值给他,谢谢
                    item.onclick = function()
                    {
                        //进行验证
                        //判断当前验证的组
                        var group = "YK_VALIDATOR";
                        if (typeof (item.validatorGroup) != "undefined")
                        {
                            group = item.validatorGroup;
                        }
                        if ($.validator.valid(group) == false)
                        {
                            return false;
                        }
                        if (typeof (fun) != "undefined")
                        {
                            fun();
                        }
                    };
                };
      

  3.   

    item.onclick = function()
     {//有什么问题?这里的this就是item对象了,不用传了}
      

  4.   


                    item.onclick = function()
                    {
                        //进行验证
                        //判断当前验证的组
                        var group = "YK_VALIDATOR";
                        if (typeof (item.validatorGroup) != "undefined")
                        {
                            group = item.validatorGroup;
                        }
                        if ($.validator.valid(group) == false)
                        {
                            return false;
                        }
                        if (typeof (fun) != "undefined")
                        {
                            fun(this);
                        }
                    };我改为了fun(this);这里的this,在firebug中还是input,
    但当他再次转到Login(send){}方法里面,这个Send就变成了window
      

  5.   


    <!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)
            {
                alert(send.location.href);
            }
        </script>
        <script type="text/javascript">
            $(function()
            {
                var item = $(":input[type='button']").get(0);
                var fun = item.onclick;
                item.onclick = function()
                {
                    fun(this);
                };
            });
        </script>
    </head>
    <body>
        <input type="button" value="登录" onclick="Login(this)">
    </body>
    </html>上面是我的测试代码,这里alert出来的是网址谢谢,而不是button本身
      

  6.   


    var item=$(":submit")[0];
        var fun=item.onclick;
        item.onclick=function() {
            alert(this.nodeName+"1");
            fun.call(this);//使用call方法,将this指针传进去 
        }
      

  7.   

    哈哈可以了,还是call好用
    明天看看call的用法
    谢谢