gpt4 book ai didi

javascript - 单击时的 div 重定向到另一个 HTML 页面并调用 javascript 以显示特定的 div

转载 作者:行者123 更新时间:2023-11-30 08:58:04 25 4
gpt4 key购买 nike

我有两个 html 文件,即 FIRST.html 和 SECOND.html

FIRST.html 具有 ID 为 A1 到 A100 的 DIV,SECOND.html 具有 ID 为 B1 到 B100 的 DIV

单击 FIRST.html 中的特定 DIV 时,我想将用户重定向到 SECOND.html 并显示相应的 DIV。

例如,如果用户点击 FIRST.html 中的 DIV id=A10,他应该被重定向到 SECOND.html 并显示 DIV id=B10。

我需要考虑如何做到这一点,我想知道我们是否可以将一些参数从一个页面传递到另一个页面,然后使用这些参数调用 javascript。

谢谢!

最佳答案

你可以尝试这样的事情:

将此添加到 FIRST.html

$(document).ready(function() {
$('div').click(function () {
id = $(this).attr('id').substring(1);
window.location = 'SECOND.html?id=' + id;
});

var getVar = location.search.replace('?', '').split('=');
$('div[id$=' + getVar[1] + ']')[0].scrollIntoView();
});

将此添加到 SECOND.html

$(document).ready(function() {
$('div').click(function () {
id = $(this).attr('id').substring(1);
window.location = 'FIRST.html?id=' + id;
});

var getVar = location.search.replace('?', '').split('=');
$('div[id$=' + getVar[1] + ']')[0].scrollIntoView();
});

关于javascript - 单击时的 div 重定向到另一个 HTML 页面并调用 javascript 以显示特定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11714819/

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