单击按钮时返回新的onclick

时间:2014-05-30 15:59:15

标签: html model-view-controller onclick return

现有代码如下,但我想添加一个新的onclick,它会返回一个弹出框,询问用户是否确定要删除个人资料。虽然不能弄清楚..

现有代码:

 @if(mode == "Edit"){
        <div class="Delete"><a class="btn btn-danger" href ="@Url.Action("Delete", "GPS", new { Id = Model.provider.Company.Id.Value, oem = Model.provider.Id})">Delete Profile</a></div>  
        }

我尝试添加它,但它没有合作。

 new { onclick = "return confirm('Are you sure you want to delete the profile?')"})

1 个答案:

答案 0 :(得分:1)

在你的js中它应该是这样的:

if (confirm('Are you sure you want to delete the profile?')){
   // code to execute if ok is pressed
   // in your case it could be a redirection to the url you need
} else {
   // code if canceled is pressed, may not be used
}

要知道的是它的工作原因如果确定将返回true,如果取消则返回false。

http://www.w3schools.com/js/js_popup.asp

相关问题