gpt4 book ai didi

Jquery 中断 Href 点击

转载 作者:行者123 更新时间:2023-12-01 03:29:12 26 4
gpt4 key购买 nike

我有一个带有 Jquery 的 MVC 应用程序;我有一个包含一些数据的 GridView 和一个指向 Controller 新操作的元素。现在我需要在执行操作之前进行一些验证。我的代码是这样的:

$('#datosCartolaSeguro a').click(function(e) {

var datosProductoSeleccionado = $(this).parent().find('input').val();
$.post(pathSite + 'PorSegurosCartola/ProductoTieneCartola',
{
strDatosProducto: datosProductoSeleccionado
},
function(resp) {
if (resp == 'False') {
popupActual = '#popupProdNoTieneCartola';
centrarPopup();
cargarPopup();

}
else {
mostrarVentanaAdvertencia();
return true;
}
}
);
});

调用方法后:cargarPopup() 我想避免执行操作链接的单击。我尝试使用简单的 return false,但页面会进行回发。我还尝试使用函数 e.preventDefault();该解决方案已发布在该论坛的其他解决方案中,但不起作用。我需要避免点击 ActionLink 但没有回发。谢谢。

最佳答案

在点击函数末尾添加return false:

$('#datosCartolaSeguro a').click(function(e) {

var datosProductoSeleccionado = $(this).parent().find('input').val();
$.post(pathSite + 'PorSegurosCartola/ProductoTieneCartola',
{
strDatosProducto: datosProductoSeleccionado
},
function(resp) {
if (resp == 'False') {
popupActual = '#popupProdNoTieneCartola';
centrarPopup();
cargarPopup();

}
else {
mostrarVentanaAdvertencia();
return true;
}
}
);
return false;
});

关于Jquery 中断 Href 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1974713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com