【问题标题】:sweet alert 2 gem confirm box redirect to link after pressing oksweet alert 2 gem 确认框在按下 ok 后重定向到链接
【发布时间】:2020-12-11 00:56:28
【问题描述】:

我不确定为什么 ok 或 cancel 不做任何事情,无论如何我希望有人按下 ok 将其重定向到链接

<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文件中

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 .

在 application.scss 中

 *= require_self
 *= require sweetalert2
 *= require_tree .
 */

【问题讨论】:

    标签: javascript ruby-on-rails sweetalert sweetalert2


    【解决方案1】:

    您必须使用.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";
        }
      });
      
    }
    

    【讨论】:

    • 感谢您的回答,但我无法按确定或取消
    • 你能在 JSFiddle 中复制你的错误并显示吗?
    • sweetalert2.js:223 SweetAlert2:未知参数“closeOnConfirm” sweetalert2.js:223 SweetAlert2:未知参数“closeOnCancel”警告@ sweetalert2.js:223
    • 还是一样。我用额外的代码更新了我的问题
    • 你能在 JSFiddle 中重新创建问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多