【发布时间】:2021-05-07 11:03:59
【问题描述】:
我有以下sweet alert 2 消息:
<button onclick='
Swal.fire({
title: "Select a page you want to be redirected:",
showDenyButton: true,
showCancelButton: true,
confirmButtonText: "Home",
denyButtonText: "About",
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire("Saved!", "", "success");
} else if (result.isDenied) {
Swal.fire("Changes are not saved!", "", "info");
}
});
'>SHOW SWEET ALERT</button>
设计看起来还不错,但问题是我无法执行.erb 命令,而是显示另一条甜蜜的警报消息!
例如,如果我将上面的代码更改为以下代码,它会搞砸一切,我不知道是什么原因造成的!:
<button onclick='
Swal.fire({
title: "Select a page you want to be redirected:",
showDenyButton: true,
showCancelButton: true,
confirmButtonText: "Home",
denyButtonText: "About",
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
<%= link_to "Home Page", root_path, class:"navbar-brand" %>
} else if (result.isDenied) {
<%= link_to "About Page", home_about_path, class:"nav-link" %>
}
});
'>SHOW SWEET ALERT</button>
代码片段 2 将给出以下错误:Uncaught SyntaxError: Unexpected token '<'
【问题讨论】:
标签: javascript html ruby-on-rails erb sweetalert2