gpt4 book ai didi

javascript - 我可以使用 javascript 重定向触发事件吗?

转载 作者:行者123 更新时间:2023-11-28 00:40:22 25 4
gpt4 key购买 nike

我有一个重定向:

<script>setTimeout(function() { window.location = '/'; }, 2000);</script>

效果很好,但我想“触发事件”:

$('#languagepopup').modal('show')

同时。

在 html 中,我会使用一个类似以下内容的按钮:

onclick="$('#languagepopup').modal('show')"

如何通过重定向来做到这一点?

非常感谢任何帮助!

最佳答案

在 URL 中设置哈希值,如下所示:

<script>setTimeout(function() { window.location = '/#showModal'; }, 2000);</script>

然后在准备好的处理程序中,查找哈希并显示您的模式

$(document).ready(function () {
if (window.location.hash.indexOf('showModal') !== -1) {
window.location.hash = ''; // remove the hash
jQuery('#languagepopup').modal('show');
}
});

关于javascript - 我可以使用 javascript 重定向触发事件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28015662/

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