![](/img/trans.png)
[英]Rails 3 - Javascript :confirm not working for link_to and button_to with :method => :delete
[英]How to use plain javascript to delete with confirm in rails?
我的項目中沒有jquery_ujs,因此,當我單擊刪除按鈕時,我試圖彈出一個窗口。
但是,即使我按“取消”或“確定”,該項目也將被刪除。
這是代碼:
= button_to "Remove Item", item, method: :delete, onclick: 'remove_item()'
function remove_item(event){
if (!confirm('Are you sure, you want to delete the item')) {
event.preventDefault();
}
}
你能幫我解決這個問題嗎? 謝謝。
您必須在onclick屬性中傳遞event
,實際上您只是在使用函數而不傳遞參數,請嘗試:
= button_to "Remove Item", item, method: :delete, onclick: 'remove_item(event)'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.