2013-03-06 90 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