为了账号安全,请及时绑定邮箱和手机立即绑定

Sweet Alert 2 gem 确认框按确定后重定向到链接

Sweet Alert 2 gem 确认框按确定后重定向到链接

叮当猫咪 2023-11-11 21:18:06
我不确定为什么“确定”或“取消”没有做任何事情,无论如何我希望当有人按“确定”将其重定向到链接时<div class="popup" onclick="sweetalertclick()">              <p id="center"><%= image_tag "pickup.png" ,width: "80px"%><br>                <span  onclick="sweetalertclick()"></span>Request a DDS pick u                </span>              </p>            </div>    <script>    function sweetalertclick() {        swal({        title: "Request a DDS",        text: "Please log in to DDS website to request a pick up, my code is: xxxx. By pressing ok you will link to google.com",        showCancelButton: true,        confirmButtonColor: "#DD6B55",        confirmButtonText: "Ok",        cancelButtonText: "Cancel",        closeOnConfirm: false,        closeOnCancel: false,      },      function(isConfirm){        if (isConfirm) {          window.location.href = "google.com"        }      }    );          }    </script>在宝石文件中gem 'rails-assets-sweetalert2', source: 'https://rails-assets.org'gem 'sweet-alert2-rails'gem 'sweet-alert-confirm'在 application.js 中//= require sweetalert2//= require jquery//= require jquery_ujs//= require sweet-alert2-rails//= require cocoon //= require sweet-alert-confirm  //= require_tree .在应用程序.scss中 *= require_self *= require sweetalert2 *= require_tree . */
查看完整描述

1 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

您必须使用.then()并在其中传递重定向过程:


例子:


function sweetalertclick() {


swal({

    title: 'Request a DDS',

    text: "Please log in to DDS website to request a pick up, my code is: xxxx. By pressing ok you will link to google.com",

    showCancelButton: true,

    confirmButtonColor: "#DD6B55",

    confirmButtonText: "Ok",

  }).then((result) => {

  console.log(result)

    if (result) {

      window.location.href = "google.com";

    }

  });

  

}


查看完整回答
反对 回复 2023-11-11
  • 1 回答
  • 0 关注
  • 83 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信