【发布时间】:2018-09-24 20:36:09
【问题描述】:
**
function bindSweetAlertButtonDemo() {
const swalButton = document.getElementById('sweet-alert-demo');
if (swalButton) { // protect other pages
swalButton.addEventListener('click', () => {
swal({
title: "Nice",
text: "You've added a task. Click on it for more details",
icon: "success"
});
event.preventDefault()
});
}
}
<div>
<%= simple_form_for [ @task] do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit :submit, class: "btn btn-danger" ,id: "sweet-alert-demo" %>
<% end %>
</div>
我试图制作一个带有提交按钮的表单,以将任务添加到索引页面。在提交时,我想要一个成功的甜蜜警报。然而,警报首先在几毫秒后消失,但通过 preventdefault() 解决了这个问题。但是现在提交实际上不再起作用了。有任何想法吗? (我已经正确导入了东西,只是没有在sn-p中添加)
【问题讨论】:
-
你没有定义
event应该是('click', (event) => ... -
您是否在 html 中添加 文件以进行甜蜜警报,能否请您提供错误以供我们检查
标签: javascript html ruby-on-rails sweetalert