【问题标题】:New onclick return when clicking on button单击按钮时新的onclick返回
【发布时间】:2014-05-30 15:59:15
【问题描述】:

现有代码如下,但我想添加一个新的 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?')"})

【问题讨论】:

    标签: html model-view-controller onclick return


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2020-04-25
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多