单击引导模式锚点时添加 URL 哈希

Add URL hash when on click bootstrap modal anchor

本文关键字:添加 URL 哈希 模式 单击      更新时间:2023-09-26

我有一个锚点来打开一个模态:

<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

在 show.bs.modal 上更改 url 哈希 引导模式的事件 (docs)

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