我试图将index.html与一个href链接链接到players.html - > Pele 标签。
以下是我的 index.html 代码:
<a href="players.html#client-panel-2"></a>
和我的 players.html
<ul data-tabs="data-tabs" id="example-tabs" class="tabs">
<li class="tabs-title is-active" tab-community-amenities="tab-community-amenities"
role="presentation">
<div class="tabs-link" data="#client-panel-0" role="tab" aria-controls="client-panel-0"
aria-selected="false" id="client-panel-0-label">Messi
</div>
</li>
<li class="tabs-title" tab-apartment-amenities="tab-apartment-amenities" role="presentation">
<div class="tabs-link" data="#client-panel-1" role="tab" aria-controls="client-panel-1"
aria-selected="false" id="client-panel-1-label">Pele
</div>
</li>
<li class="tabs-title" tab-pet-policy="tab-pet-policy" role="presentation">
<div class="tabs-link" data="#client-panel-2" role="tab" aria-controls="client-panel-2"
aria-selected="false" id="client-panel-2-label">Kaka
</div>
</li>
<li class="tabs-title" tab-parking-details="tab-parking-details" role="presentation">
<div class="tabs-link" data="#client-panel-3" role="tab" aria-controls="client-panel-3"
aria-selected="false" id="client-panel-3-label">Benzema ;)
</div>
</li>
<li class="tabs-title" tab-parking-details="tab-parking-details" role="presentation">
<div class="tabs-link" data="#client-panel-4" role="tab" aria-controls="client-panel-4"
aria-selected="false" id="client-panel-4-label">Berbatov
</div>
</li>
</ul>
答案 0 :(得分:1)
使链接包含某种url变量
<a href="players.html?selected=pele-id></a>
使用jquery很好看
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
添加一个id标签,以便于使用jquery
查找<div id="pele-id" class="tabs-link" data="#client-panel-2" role="tab" aria-controls="client-panel-2"
aria-selected="false" id="client-panel-2-label">
在脚本标记中获取该值。然后编辑attr aria-selected(我认为这是你试图改变的)。
<script>
var url = new URL(window.location.href);
var selector = url.searchParams.get("selected");
$("#" + selector).attr("aria-selected", "true")
</script>
假设将attr更改为“true”将执行您想要的操作,这应适用于所有不同的