【问题标题】:Submit button confirm for delete not working in rails 3提交按钮确认删除在rails 3中不起作用
【发布时间】:2013-03-06 07:55:20
【问题描述】:

我对 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'} %>

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

【问题讨论】:

  • 如果您按 OK,confirm() 返回 True,如果您按取消,则返回 False。你没有对确认返回的值做任何事情。

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


【解决方案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?');
    };
});

【讨论】:

  • 不,实际上不是(我也这么认为哈哈),他返回确认响应...我还要再等几分钟才能接受你的回答哈哈,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 2016-09-21
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
相关资源
最近更新 更多