[英]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.