关于$(this)的问题
时间:2009-12-15
来源:互联网
function removeAddr(e,id) {
if (confirm('你确定要删除这个地址吧?'))
{
$.ajax({
url : BASEURL+'order/updateAddrStatus',
type : 'post',
data : {id:id},
dataType : 'text',
beforeSend:function(){
$('#loadMask').show();
},
complete:function(){
$('#loadMask').hide();
},
success : function(msg){
e.closest('tr').remove();
}
});
} else {
return false;
}
}
<a title="删除" onclick="removeAddr($(this),{[$address[s].id]})">删除</a>
这样$(this)在success的function里面有效的。
-------------------------------------------------------------------------------------------------------------------
$('.del').click(function(){
if (confirm('你确定要删除这个地址吧?'))
{
$id = $(this).attr('title'); //在这里$(this)还是有效的
$.ajax({
url : BASEURL+'order/updateAddrStatus',
type : 'post',
data : {id:$id},
dataType : 'text',
beforeSend:function(){
$('#loadMask').show();
},
complete:function(){
$('#loadMask').hide();
},
success : function(msg){
$(this).closest('tr').remove(); //在这里$(this)是无效的
}
});
} else {
return false;
}
});
<a title="删除" title="{[$address[s].id]}">删除</a>
在这里$(this)在success的function里是无效的
-----------------------------------------------------------------------------------------------------------------
请问各位高手我的问题出在哪里呢?
if (confirm('你确定要删除这个地址吧?'))
{
$.ajax({
url : BASEURL+'order/updateAddrStatus',
type : 'post',
data : {id:id},
dataType : 'text',
beforeSend:function(){
$('#loadMask').show();
},
complete:function(){
$('#loadMask').hide();
},
success : function(msg){
e.closest('tr').remove();
}
});
} else {
return false;
}
}
<a title="删除" onclick="removeAddr($(this),{[$address[s].id]})">删除</a>
这样$(this)在success的function里面有效的。
-------------------------------------------------------------------------------------------------------------------
$('.del').click(function(){
if (confirm('你确定要删除这个地址吧?'))
{
$id = $(this).attr('title'); //在这里$(this)还是有效的
$.ajax({
url : BASEURL+'order/updateAddrStatus',
type : 'post',
data : {id:$id},
dataType : 'text',
beforeSend:function(){
$('#loadMask').show();
},
complete:function(){
$('#loadMask').hide();
},
success : function(msg){
$(this).closest('tr').remove(); //在这里$(this)是无效的
}
});
} else {
return false;
}
});
<a title="删除" title="{[$address[s].id]}">删除</a>
在这里$(this)在success的function里是无效的
-----------------------------------------------------------------------------------------------------------------
请问各位高手我的问题出在哪里呢?
作者: zhuzuoling 发布时间: 2009-12-15

作者: zhuzuoling 发布时间: 2009-12-27
看不懂 大家帮忙顶一下
_____________________________
TaylorMade R9 Fairway Wood,TaylorMade R9 Driver,TaylorMade R9 Irons,Ping G15 DriverTitleist AP2 Irons
_____________________________
TaylorMade R9 Fairway Wood,TaylorMade R9 Driver,TaylorMade R9 Irons,Ping G15 DriverTitleist AP2 Irons
作者: banghao123 发布时间: 2009-12-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28