我有以下用于删除项目的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
}
}
我在几个ActionLinks中使用这个函数:
@Html.ActionLink("Delete", "Delete", new { route values here }, new { onclick = "deleteItem('" + ItemToDeleteName + "');"})
它可以在IE和Chrome上正常运行,但在FireFox中无效。我将不胜感激任何帮助。谢谢!
答案 0 :(得分:4)
您需要使用return
之类的
new { onclick = "return deleteItem('" + ItemToDeleteName + "');"}
此外,您应该根据执行将继续或中断的函数true/false
返回deleteItem()