[英]How to use plain javascript to delete with confirm in rails?
I don't have jquery_ujs in my project, So I am trying to get a pop up when clicked on a delete button. 我的项目中没有jquery_ujs,因此,当我单击删除按钮时,我试图弹出一个窗口。
But the item is getting deleted, even if I press cancel or ok. 但是,即使我按“取消”或“确定”,该项目也将被删除。
Here is the code: 这是代码:
= 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();
}
}
Can you help me solve this? 你能帮我解决这个问题吗? Thank you.
谢谢。
您必须在onclick属性中传递event
,实际上您只是在使用函数而不传递参数,请尝试:
= button_to "Remove Item", item, method: :delete, onclick: 'remove_item(event)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.