单击引导时模态锚点时添加URL哈希 [英] Add URL hash when on click bootstrap modal anchor

查看:93
本文介绍了单击引导时模态锚点时添加URL哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个锚来打开模态:

I have an anchor to open a modal:

<a href="#delete-{{ $id }}" class="btn btn-danger btn-xs btn-delete btn-fla details" data-toggle="modal" data-target="#remove_property_modal">
    <i class="fa fa-trash"></i>
</a>

问题是网址没有从http://example.com更改为http://example.com/#delete-4.

The problem is that the url is not changing from http://example.com into http://example.com/#delete-4 .

推荐答案

更改bootstrap modal的show.bs.modal事件上的url哈希(文档)

Change url hash on show.bs.modal event of bootstrap modal (docs)

$(document).ready(function () {
     $('.modal').on('show.bs.modal', function (e) {
         if (typeof (e.relatedTarget) != "undefined") {
             window.location.hash = $(e.relatedTarget).attr('href');
         } 
     });
});

这篇关于单击引导时模态锚点时添加URL哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆