简体   繁体   English

如何使用jQuery将链接重定向到引导模式

[英]How to make a link redirect to a bootstrap modal with jQuery

I have a link that redirects to a product page by it's id, but I want to show a modal before it redirects. 我有一个通过其ID重定向到产品页面的链接,但是我想在重定向之前显示一个模式。 I would like the user to confirm that he has read it, and only redirect if he confirms, otherwise he would stay at the same page. 我希望用户确认他已经阅读过,并且仅在他确认后才重定向,否则他将停留在同一页面上。 (I apologize for the bad English) (我为英语不好表示歉意)

You may find this example useful: http://www.bootply.com/63844 您可能会发现此示例很有用: http : //www.bootply.com/63844

$('#btnYes').click(function() {
    // handle redirect here
    var link = $('#myModal').data('link');
    location.href = link;
    $('#myModal').modal('hide');
});

It uses a click handler on the link to trigger the modal, and then does the redirection once a button ( #btnYes ) inside the modal is clicked. 它使用链接上的单击处理程序来触发模式,然后在模式中的按钮( #btnYes )被单击后执行重定向。 The redirect link is defined using a data attribute on the link. 使用链接上的数据属性定义重定向链接。

首先,链接到模态,然后如果单击某个按钮,则从模态链接到产品页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM