由于jquery的代码
是Function作用域,而
success:function(strValue){}的作用域改变了,因此在该作用域下使用$(this)并不能找到当前对象。
比较简单的解决办法是在调用ajax之前保存一下当前的this变量。
比如:
$(function(){
$(".yourClass").each(function(){
var Price = $(this).html();
var $this = $(this);
$.ajax({
async: false,
type: "POST",
url:"modifyPriceAction.action",
dataType:"html",
data:{price:Price},
success:function(strValue){
$($this).html(strValue);
}
})
})
})