0

我有这个 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>
4

1 回答 1

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
    });
});
于 2013-02-19T11:55:40.403 回答