提交按钮确认删除不在rails 3中工作

时间:2013-03-06 07:55:20

标签: javascript jquery ruby-on-rails submit destroy

我还是铁杆新手,在删除多个项目时尝试了解某些​​内容。当我单击提交时,它可以工作,我可以删除多个项目,但是,无论我的确认响应如何,它都会删除。

我正在使用javascript来检测提交按钮的onclick事件,我的代码是:

$('.delete').on('click', function(){
    checked = countChecked();
    if (checked > 1) {
        confirm('Are you sure you want to delete these ' + checked + ' entries?');
    } else {
        confirm('Are you sure you want to delete this entry?');
    };
});

我的提交按钮是:

<%= submit_tag "Delete Selected", { :class => 'delete'} %>

为什么确认没有做正确的事情?即使按下取消,它也会删除...

1 个答案:

答案 0 :(得分:1)

试试这个

$('.delete').on('click', function(){
    checked = countChecked();
    if (checked > 1) {
       return confirm('Are you sure you want to delete these ' + checked + ' entries?');
    } else {
       return confirm('Are you sure you want to delete this entry?');
    };
});