gpt4 book ai didi

javascript - 停止将 HTML href 连接到地址栏

转载 作者:太空宇宙 更新时间:2023-11-04 00:34:57 24 4
gpt4 key购买 nike

我有一个带有一些按钮的btn-group,每个按钮都会指向不同的页面。 btn-group 将在每个页面上可见。

这是 btn-group 的 html,


<div class="btn-group-lg text-center" role="group" aria-label="Basic example">

<a class="btn btn-outline-primary" href="" role="button">Home</a>
<a class="btn btn-outline-primary" href="view_schedule/" role="button">Schedule</a>
<a class="btn btn-outline-primary" href="view_syllabus/" role="button">Syllabus</a>
<a class="btn btn-outline-primary" href="view_records/" role="button">Records</a>
<a class="btn btn-outline-primary" href="view_achievements/" role="button">Achievements</a>
<a class="btn btn-outline-primary" href="view_gallery/" role="button">Gallery</a>
<a class="btn btn-outline-primary" href="view_contact/" role="button">Contact</a>
<a class="btn btn-outline-primary" href="about/" role="button">About Us</a>

</div>

但是每当我按下按钮时,它都会修改地址栏中的 URL。示例:- 来自 http://127.0.0.1:8000/shotokankaratebd/ ,如果我按下“计划”按钮,它会将 URL 更改为 http://127.0.0.1:8000/shotokankaratebd/view_schedule .

在那之后,如果我再次按下日程安排按钮,它将变为 http://127.0.0.1:8000/shotokankaratebd/view_schedule/view_schedule这是一个无效的 URL,我得到了一个错误。

我如何编写它以便每当按下按钮时,只有 http://127.0.0.1:8000/shotokankaratebd/ 之后的部分有影响吗?

编辑以包含新的 hrefs:


<a class="btn btn-outline-primary" href="../shotokankaratebd/" role="button">Home</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_schedule/" role="button">Schedule</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_syllabus/" role="button">Syllabus</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_records/" role="button">Records</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_achievements/" role="button">Achievements</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_gallery/" role="button">Gallery</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/view_contact/" role="button">Contact</a>
<a class="btn btn-outline-primary" href="../shotokankaratebd/about/" role="button">About Us</a>

最佳答案

您不应该对您的网址进行硬编码。使用 django's url template tag为您的 View 获取 url。

关于javascript - 停止将 HTML href 连接到地址栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59698399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com