【问题标题】:Opening show page in a modal with updating url in address bar using HTML & JS使用 HTML 和 JS 在地址栏中更新 url 以模式打开显示页面
【发布时间】:2020-07-26 19:49:24
【问题描述】:

我想获取地址栏中按钮单击的 id,以便像 instagram 那样从数据库中获取 relivent 数据。 我想使用 php 从地址栏获取 id 以根据所选参考的 id 从数据库中查找特定数据。

注意 下图是@designer 来自Stackoverflow Question 的致谢。

我的代码片段是:

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>


<a    class="btn btn-primary btnModal"  data-target ="#scrapModal"  href="washingPlan.php#scrapModal?id=' . $row['id'] . '" data-toggle="modal" >Service Include</a>


<div class="modal fade bd-example-modal-lg" id="scrapModal" tabindex="-1" role="dialog" aria-labelledby="scrapModal" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">


                        <!-- DataTales Example -->
                        <div class="card shadow mb-4">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">WASHING PLAN SERVICES</h6>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                
                                    <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <input type="text" name="id" id="id" />

                                        <thead>
                                            <tr>
                                                <th>S.No.</th>
                                                <th>Washing plan Services</th>
                                                <th>Action</th>

                                            </tr>
                                        </thead>
                                        <tfoot>
                                            <tr>
                                                <th>S.No.</th>
                                                <th>Washing plan Services</th>
                                                <th>Action</th>
                                            </tr>
                                        </tfoot>
                                        <tbody>


                                        


        <tr>
        <th>test</th>
        <th>test1</th>
        <th>test2</th>
    </tr>

                                        
                                            
                                   
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <form action="" method="post">

                            <div class="col-lg-8 m-4">
                                <label class="ml-1">Plans Include</label><br>
                                <input type="text" id="plans" name="plans" placeholder="" class="col-12" required>
                            </div>

                            <div class="row m-5">
                                <input type="submit" value="Reset" class="btn" style="background-color: #FF9933;letter-spacing: 0.6px;border-radius: 2px;color: #FFF;">
                                <input type="submit" class="btn" name="includeService" value="Add Value" style="background-color: #0891FF;;letter-spacing: 0.6px;border-radius: 2px;color: #FFF; display: inline-block;vertical-align: middle;">
                            </div>
                        </form>


                    </div>
                </div>
            </div>

当我添加 data-target=modal 时,它的地址没有改变。有什么技术可以制作这样的模态吗?

提前谢谢你

【问题讨论】:

    标签: javascript html bootstrap-modal href


    【解决方案1】:

    我会说您正在寻找History API,它允许您使用 JS 操作浏览器历史记录(包括 URL 栏)。

    history.pushState() 允许您将页面“添加”到历史堆栈,这会将 URL 更改为您指定的任何内容。

    如果您监听window.onpopstate 事件,您可以检测用户何时使用浏览器控件(例如后退按钮)导航历史,中断它并自行处理,而无需重新加载页面!

    这应该足以让您入门,这是一个非常有用的 API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 2011-03-15
      • 2023-03-28
      • 2016-07-28
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      相关资源
      最近更新 更多