onclick="confirm()" 取消按钮不起作用

Cha*_*thz 1 html javascript jquery button asp.net-mvc-4

我有 grid ,在那个 grid 中,对于特定的记录,我保持活动/非活动状态。这是对该状态的看法

在此处输入图片说明

当我单击活动按钮时,它会显示此警报消息。

在此处输入图片说明

但是当我单击取消按钮时,我无法停止将处于活动状态的操作。

这是此活动/非活动按钮的 html 代码片段

   @if (item.Status == true)
                       {
                           <button class="btn btn-xs active btn-primary" data-HEI_ID = "@item.HEI_ID" data-status = "true"  onclick="confirm_active()">Active</button>                       
                            <button class="btn btn-xs inactiveColor btn-default" data-HEI_ID = "@item.HEI_ID" data-status = "false"  onclick="confirm_inactive()">Inactive</button>

                       }

                       else
                       {
                           <button class="btn btn-xs btn-default" data-HEI_ID = "@item.HEI_ID" data-status = "true"  onclick="confirm_active()">Active</button>                       
                           <button class="btn btn-xs inactiveColor btn-primary active" data-HEI_ID = "@item.HEI_ID" data-status = "false"  onclick="confirm_inactive()">Inactive</button>

                           }
Run Code Online (Sandbox Code Playgroud)

这是警报消息的脚本部分

<script type="text/javascript">
function confirm_active() {
    var retVal = confirm("Are you sure you want to change the status to Active?");
    if (retVal == true) {
        // do stuff
        return true;
    } else {
        return false;
    }
}

function confirm_inactive() {
    var retVal = confirm("Are you sure you want to change the status to Inactive?");
    if (retVal == true) {
       // do stuff
        return true;
    } else {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何制作可用的取消按钮

Adi*_*dil 5

您错过returnonclick处理程序中的语句。作为附加说明,用分号结束函数调用的好习惯

改变

 onclick="confirm_active()"
Run Code Online (Sandbox Code Playgroud)

 onclick="return confirm_active();"
Run Code Online (Sandbox Code Playgroud)

同样适用于confirm_inactive()