2013-03-06 51 views
0

我还是新来的铁轨和试图理解东西时删除多个项目。当我点击提交时,它可以工作,我可以删除多个项目,但是,无论我的确认响应如何,它都会删除。提交按钮确认删除不工作在rails 3

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

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

+2

的确认()如果按OK和False如果按取消返回True。您对通过确认返回的值无效。 – 2013-03-06 07:58:36

回答

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?'); 
    }; 
}); 
+0

这是相同的代码在他的问题 – nimrod 2013-03-06 08:01:03

+0

没有它实际上(我认为太哈哈),他返回确认响应...我必须再等几分钟接受你的答案哈哈,谢谢! – GiH 2013-03-06 08:02:19

+0

你有没有得到它的工作? – 2013-03-06 09:07:23