简体   繁体   English

Javascript确认对话框和中/右键单击

[英]Javascript confirm dialog and middle/right mouse click

I'm working on an ASP.NET MVC 3 project, and I want to display a confirmation message before deletion, I've wrote the following line: 我正在开发一个ASP.NET MVC 3项目,我想在删除之前显示一条确认消息,我写了以下这一行:

@Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are you sure?')" })

Which is ok and works fine, however when I click middle button on the mouse or right click then choose 'Open Link in New Tab', the record will be deleted without displaying the confirm dialog which is weird! 哪个好,工作正常,但是当我单击鼠标中键或右键单击然后选择“在新标签中打开链接”时,记录将被删除而不显示确认对话框,这很奇怪!

I have tried the upper code with onMouseDown , the dialog displays but no action is happening when I click on OK button! 我用onMouseDown尝试了上面的代码,对话框显示但是当我点击OK按钮时没有动作! (the record wont be deleted) (记录不会被删除)

My question is how can I display a confirmation message before I delete a record and that link will only respond to left mouse click? 我的问题是如何在删除记录之前显示确认消息,该链接只会响应鼠标左键单击?

You should check mouse key on 'onclick' event and then return false if key is left. 您应该在'onclick'事件上检查鼠标键,如果还剩下键,则返回false。 See useful example: Issue with onClick() and middle button on mouse 请参阅有用的示例: 鼠标上的onClick()和中间按钮问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM