javascript - 如何链接回我的 index.html 上的选项卡?

标签 javascript html css

我在 https://gallant-euclid-b426b2.netlify.com 上有三个元素选项卡

当您点击一个元素时,您将被定向到一个新页面。我希望标签在那个新页面上工作。我该如何做到这一点?因此,“学校”选项卡将链接回 index.html 上的学校选项卡,“元素”选项卡将链接回元素选项卡。

(返校选项卡实际上已经可以使用了,因为这是默认选项卡)

我不想使用 history.back(),因为有人可能会向某人发送元素链接,然后可能没有上一页等。

<div class="bar">
    <div class="tab">
        <button class="tablinks" id="defaultopenTab" onclick="openTab(event, 'school')">school</button>
        <button class="tablinks" onclick="openTab(event, 'projects')">projects</button>
        <button class="tablinks" onclick="openTab(event, 'about')">about</button>
    </div>
</div>

我希望有一个解决方案,我可以简单地说:

onclick="location.href='index.html'; openTab(event, projects)"

最佳答案

页面office.html中的标签代码需要与index.html中的相同

<div id="school" class="tabcontent">
    <h1>industrial design</h1>
    <div class="project" onclick="location.href='office.html';">
        <div class="img" id="some"></div>
        <div class="name">Project 1</div>
        <div class="label">Industrial Design</div>
    </div>
    <div class="project" onclick="location.href='office.html';">
        <div class="img" id="some"></div>
        <div class="name">Project 2</div>
        <div class="label">Industrial Design</div>
    </div>
    <div class="project_long" onclick="location.href='office.html';">
        <div class="img_long" id="stage"></div>
        <div class="name">Stage</div>
        <div class="label">Industrial Design</div>
    </div>
    <div class="project" onclick="location.href='office.html';">
        <div class="img" id="office"></div>
        <div class="name">Office Rating System</div>
        <div class="label">Industrial Design</div>
    </div>
</div>

您可以通过复制和粘贴或通过脚本静态地执行此操作。 例如,您可以将每个选项卡绑定(bind)到一个共享的 javascript 文件。

改变

<div class="project" onclick="location.href='office.html';">

<div class="project" id="office">

然后在脚本中

$(document).on("click","#office",function(){
   windows.open("office.html","_self");
});

对每个选项卡执行此操作。

关于javascript - 如何链接回我的 index.html 上的选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57982025/

相关文章:

javascript - 运行 jQuery,重新加载,冲洗并重复......如何?

php - 从 Mysql 检索日期并将其溢出到特定列表

jquery - jQuery GUI 开发的良好实践

javascript - jQuery 数据表处理 Null 子对象

JavaScript 无法在 'getComputedStyle' : parameter 1 is not of type 'Window' 上执行 'Element'

javascript - 如何制作 HTML5 旋转列表/旋转轮选择器/选择器

php 查找div的内容

html - 嵌套 div 中的 margin-top

JavaScript - 使用纯 JavaScript 切换 CSS 颜色?

javascript - Bootstrap-datepicker inline 以短格式点击获取日期