如果您有具有相同类但不同值的字段我知道有一种方法可以在jQuery中使用$(this)发送值,但是当返回函数结果时,我想更新已点击的特定字段?我如何做到这一点$(this)正在改变每个领域与同一个班级。如何在具有相同类jquery的特定字段中返回值
类是在循环中自动生成的,我不想为每个字段使用不同的类。
必须有一种方法,我很想念实现这个
这里是我的代码。
$(".voteclick").click(function() {
var dynname = $(this).attr('name');
var votevalue = $(this).next().val();
$.ajax({
url:'http://localhost/wpcomnt/wp-content/themes/smart-mag-child/subrating.php',
type:"POST",
data:"dynname=" + dynname + "&" + dynname + "=" + votevalue + "&measure=" + $('#measure').val(),
dataType:'json',
success:function (mydata) {
if(votevalue == 'up') {
$(this).val('Agree: ' + mydata); // this must not change every .voteclick field it should change only the clicked one ?
}
else if(votevalue == 'down') {
$(this).val('Disagree: ' + mydata); // this must not change every .voteclick field it should change only the clicked one ?
}
//$(".voteclick").val('Agree: '+mydata);
},
error:function() {
$(".errormainbtn").slideDown();
}
});
});
请下一个读评论这一行$(this).val('Disagree: '+mydata);
有许多领域的一次我点击它,因为类是相同的,他们被改变,并且自动生成的,请告诉我一个办法让我可以改变只有我点击了类领域是
".votelick"
内阿贾克斯成功回调,'this'指的是jqXHR对象。你应该设置'context:this,'作为'$ .ajax()'方法的选项,检查DOC – 2015-01-04 13:25:02