0

我对 Rails 还是很陌生,并在删除多个项目时试图理解一些东西。当我单击提交时,它可以工作并且我可以删除多个项目,但是,无论我的确认响应如何,它都会删除。

我正在使用 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'} %>

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

4

1 回答 1

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?');
    };
});
于 2013-03-06T07:59:59.283 回答