【问题标题】:On confirm delete?确认删除?
【发布时间】:2013-02-19 19:55:40
【问题描述】:

我有这个 mootools 代码,单击按钮会删除记录,现在我想当用户单击删除按钮时弹出确认对话框,询问我是否确定要删除记录并回答是和否...这是我的代码...如果用户回答“是”以继续此请求,如果他回答“否”则不要继续,如果我有另一条消息说在他单击“是”后记录已被删除,那也很棒...

<script>
window.addEvent('domready',function() {


$$('a.delete').each(function(el) {
el.addEvent('click',function(e) {
  e.stop();
  var parent = el.getParent('div');
  var request = new Request({
    url: '/delete.php',
    link: 'chain',
    method: 'get',
    data: {
      'delete': parent.get('id').replace('record-',''),
      ajax: 1
    },
    onRequest: function() {
      new Fx.Tween(parent,{
        duration:300
      }).start('background-color', '#fb6c6c');
    },
    onSuccess: function() {
      new Fx.Slide(parent,{
        duration:300,
        onComplete: function() {
          parent.dispose();
        }
      }).slideOut();
    }
  }).send();
});
 });

});


</script>

【问题讨论】:

    标签: ajax mootools


    【解决方案1】:

    这很简单。

    if (confirm('message')){ 
        // code when yes
    }
    else {
        // code when no
    }
    

    因此。

    $$('a.delete').each(function (el) {
        el.addEvent('click', function (e) {
            e.stop();
            var parent = el.getParent('div');
            if (confirm('are you sure you want to delete this?')) {
                new Request({
                    url: '/delete.php',
                    link: 'chain',
                    method: 'get',
                    data: {
                        'delete': parent.get('id').replace('record-', ''),
                        ajax: 1
                    },
                    onRequest: function () {
                        new Fx.Tween(parent, {
                            duration: 300
                        }).start('background-color', '#fb6c6c');
                    },
                    onSuccess: function () {
                        new Fx.Slide(parent, {
                            duration: 300,
                            onComplete: function () {
                                parent.dispose();
                            }
                        }).slideOut();
                    }
                }).send();
            } // confirm
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-26
      • 2011-10-06
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-15
      相关资源
      最近更新 更多