Javascript 确认后如何修改代码删除项目?

Javascript 确认后如何修改代码删除项目?,javascript,c#,confirm,Javascript,C#,Confirm,在我确认之前,我的代码将删除项目。在我确认项目后,如何进行更改以使其删除项目。下面是javascript代码: <script type="text/javascript"> var _source; var _popup; function showChild_Delete(source) { this._source = source; this._popup = $find('popupChild_Delete');

在我确认之前,我的代码将删除项目。在我确认项目后,如何进行更改以使其删除项目。下面是javascript代码:

<script type="text/javascript">
    var _source;
    var _popup;

    function showChild_Delete(source) {
        this._source = source;
        this._popup = $find('popupChild_Delete');
        this._popup.show();
    }

    function btnChild_Delete_Click() {  
        this._popup.hide();
        __doPostBack(this._source.name, '');
    }                     
</script>

我将非常感谢您的帮助。

您可能希望在客户端用javascript做一些事情,提示他们在做决定之前接受他们的决定

function btnChild_Delete_Click() {
    if (!confirm('Are you sure you want to delete?')) return;
    this._popup.hide();
    __doPostBack(this._source.name, '');
}   
<script type="text/javascript">
    function btnChild_Delete_Click() {  
        this._popup.hide();

        // the _doPostBack is triggering the delete. simply writing something here.
        if (!confirm('Are you sure?')) return;

        __doPostBack(this._source.name, '');
    }                     
</script>
  • 更改脚本以调用显示/隐藏确认DIV的函数:

    function buttonConfirmDelete_Click {
        // 1. display the confirmation box.
    }
    
    function buttonDoDelete_Click {
        __doPostBack(this._source.name, '');
        // 2. hide the confirmation box.
    }
    
  • 结果是,您现有的删除按钮只会显示实际执行回调的删除按钮,该按钮现在包含在确认弹出窗口中

    当然有更多干净的方法可以做到这一点,但似乎您正在寻找一个快速简单的解决方案


    这就回答了你的问题吗?

    你可能想在客户端用javascript做一些事情,提示他们在做决定之前接受他们的决定

    <script type="text/javascript">
        function btnChild_Delete_Click() {  
            this._popup.hide();
    
            // the _doPostBack is triggering the delete. simply writing something here.
            if (!confirm('Are you sure?')) return;
    
            __doPostBack(this._source.name, '');
        }                     
    </script>
    
  • 更改脚本以调用显示/隐藏确认DIV的函数:

    function buttonConfirmDelete_Click {
        // 1. display the confirmation box.
    }
    
    function buttonDoDelete_Click {
        __doPostBack(this._source.name, '');
        // 2. hide the confirmation box.
    }
    
  • 结果是,您现有的删除按钮只会显示实际执行回调的删除按钮,该按钮现在包含在确认弹出窗口中

    当然有更多干净的方法可以做到这一点,但似乎您正在寻找一个快速简单的解决方案

    回答您的问题?

    包含一个完整的解决方案,使用jquery ui对话框弹出确认对话框

    您可以将它调整为您正在使用的任何javascript库。

    包含一个完整的解决方案,该解决方案使用jquery ui对话框作为弹出确认对话框


    您可以将它调整为您正在使用的任何javascript库。

    Hi。谢谢你的回复。它的作品,但给浏览器的窗口,这是不同的风格与我的网站。比如窗口的标题、颜色、大小。如何解决这个问题?我建议在代码中的某个地方为确认面板创建一个
    DIV
    ,这样您就可以像其他HTML元素一样使用CSS对其进行样式化。只需更改该行即可显示弹出窗口并获得用户响应。Hi。谢谢你的回复。它的作品,但给浏览器的窗口,这是不同的风格与我的网站。比如窗口的标题、颜色、大小。如何解决这个问题?我建议在代码中的某个地方为确认面板创建一个
    DIV
    ,这样您就可以像其他HTML元素一样使用CSS对其进行样式化。只需更改该行即可显示弹出窗口并获得用户响应。
    function buttonConfirmDelete_Click {
        // 1. display the confirmation box.
    }
    
    function buttonDoDelete_Click {
        __doPostBack(this._source.name, '');
        // 2. hide the confirmation box.
    }