首页 > Web开发 > 详细

$(this)在ajax中无效的解决方案

时间:2016-12-12 13:47:41      阅读:173      评论:0      收藏:0      [点我收藏+]

在ajax方法里写$(this)指向的是最近调用它的jquery对象,所以这里的$(this)指的是ajax对象,而不是$(".enter_caozuo").find(".gd"),要想解决这个问题,就需考虑增加一个中间变量传递这个对象,示例:
$(".enter_caozuo").find(".gd").click(function(){
var mythis = $(this);

$.ajax({
type:"GET",
url:"lanEdit.php?lanname="+lan_name,
success:function(msg){
var info = eval(‘(‘+msg+‘)‘);
var state = info.state;
mythis.parents(".yuan").siblings(".more").find(".lanname").val(info.name);
//....你的代码

}

$(this)在ajax中无效的解决方案

原文:http://www.cnblogs.com/ch-zaizai/p/6163833.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!