我具有以下用于删除项目的javascript函数:

function deleteItem(itemName){
    var confirmDelete = confirm("Are you sure you want to delete " + itemName + "?");
    if (!confirmDelete) {
        event.preventDefault(); //Tried with preventDefault
        return false; //Tried with return false
                      //Tried with both
    }
}


我在几个这样的ActionLink中使用此功能:

@Html.ActionLink("Delete", "Delete", new { route values here }, new { onclick = "deleteItem('" + ItemToDeleteName + "');"})


它在IE和Chrome上正常运行,但在FireFox中无法正常运行。我将不胜感激任何帮助。谢谢!

最佳答案

您需要像这样使用return

new { onclick = "return deleteItem('" + ItemToDeleteName + "');"}


同样,您应该根据函数将继续执行还是中断执行,从函数true/false返回deleteItem()

09-28 08:00