[英]changing image with jQuery
I have a little problem with jQuery when I'm trying to save a new row in a table, when action success an image just change but exactly here is my problem. 当我试图在表中保存一个新行时,我有一个jQuery的问题,当一个图像的动作成功只是改变但是这里是我的问题。
Here is my code : 这是我的代码:
$(document).on('click','.clsBtnGuardarHost',function(){
var i = this.name.substring(14)
var host = $("#host"+i).val();
if(host.trim() != "") {
$.post("AccionesHost.html", { host:$("#host"+i).val(),
descripcion: $("#descripcion"+i).val(),
ip: $("#ip"+i).val(),
cuentasCant: $("#cuentasCant"+i).val(),
accion:"Agregar"
}, function(mensaje) {
if(mensaje.indexOf(" ") != -1) {
alert(mensaje)
return;
} else {
$("#indice"+i).val(mensaje);
$(this).attr( {'id':'btnModificarHost'+i, 'name':'btnModificarHost'+i,});
$(this).val("");
$(this).removeClass('clsBtnGuardarHost')
.addClass('btnModificarHost');
$("#host"+i).removeClass('NclsAnchoTotal')
.addClass('clsAnchoTotal');
$("#descripcion"+i).removeClass('NclsAnchoTotal')
.addClass('clsAnchoTotal');
$("#ip"+i).removeClass('NclsAnchoTotal')
.addClass('clsAnchoTotal');
$("#descripcion"+i).attr('readonly',true)
$("#ip"+i).attr('readonly',true)
$("#host"+i).attr('readonly',true);
$("#cuentasCant"+i).attr('readonly',true);
}
});
} else {
alert("Debe ingresar un host valido para continuar")
}
});
So code in the final "else" works but it doesn't take effect... I don't know why. 因此最终“else”中的代码可以正常工作,但它不会生效......我不知道为什么。
Thanks for advance and sorry for my bad English. 感谢您提前和抱歉我的英语不好。
this
no longer refers to the clicked element. this
不再是指被点击的元素。 Set a context variable and use that in the callback from the AJAX: 设置一个上下文变量并在AJAX的回调中使用它:
$(document).on('click','.clsBtnGuardarHost',function(){
var that = $(this);
//AJAX
//callback
that.attr( {'id':'btnModificarHost'+i,
'name':'btnModificarHost'+i,
});
that.val("");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.