为什么
<input type="submit" value="登录" onclick="Login(this)" />
这里的this为是全本身这个input而是window对像呢?
谢谢,那这里要传他本身要怎么写
<input type="submit" value="登录" onclick="Login(this)" />
这里的this为是全本身这个input而是window对像呢?
谢谢,那这里要传他本身要怎么写
解决方案 »
- JQuery 的 fadeTo() 求解
- 上传图片预览
- 求一个jquery弹出层
- 获取控件的绝对位置。谢谢
- 向大家推荐一个非常不错的网站!
- 求兼容IE的方法。试了半天,实在出不来。
- ■■高分求解:公式中包含自定义函数,用正则表达式如何解析、效验呢?,示例代码如下■■
- Extjs4 store给store赋值问题
- 如何在js语句中加入HTML
- 在JS中怎样可知一个数组的个数?
- |zyciis| 用什么办法可以停止js继续执行,除了用throw new Error()方法,这样可以停止js执行,但浏览器左下角会显示有错误
- |zyciis| javascript如何抛出一个错误,有自定义的错误信息和错误号,然后在window.onerror中截取,谢谢
以下是代码<!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>
那是因为我在另一个地方把他更改了
如: //绑定执行优先
//找出当前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();
}
};
};
{//有什么问题?这里的this就是item对象了,不用传了}
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
<!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本身
var item=$(":submit")[0];
var fun=item.onclick;
item.onclick=function() {
alert(this.nodeName+"1");
fun.call(this);//使用call方法,将this指针传进去
}
明天看看call的用法
谢谢