gpt4 book ai didi

javascript - 仅在第一次访问时显示 > if( !localStorage.getItem( "runOnce") ) { 触发 anchor 链接

转载 作者:行者123 更新时间:2023-11-28 19:51:42 25 4
gpt4 key购买 nike

我有一个 JavaScript 表单,可以进行一些计算,但只想在访问者第一次进入该网站时显示它。

我尝试在我的代码之前添加

jQuery(document).ready(function($) {
if( ! localStorage.getItem( "runOnce" ) ) {

我需要触发一个链接,而不是 runOnce。您能提供有关如何执行此操作的建议吗?我从0开始学习...谢谢

最佳答案

data-slide 标签是特定 JS 脚本的自定义标签。这当然是在网站中实现“滑动”效果的代码。我一直在检查网站。使用“关于”按钮

您有一个可以滑动到容器 834 的 about 按钮。将 id about-btn 添加到其中,如下所示:

<a id="about-btn" href="http://www.inlovewithdeath.com/about-satish-modi-the-author/" class="menu-item menu-item-type-post_type menu-item-object-page" data-slide="container-834" data-name="about-satish-modi-the-author">About</a>

现在将其添加到某处,很可能是在外部脚本中,然后将其包含在内:

//  shortcut of $(document).ready().
$(function() {
// check if runOnce exists, if not run the block.
if (! localStorage.getItem('runOnce')) {
// we set the runOnce, so this block doesn't run on the second time.
localStorage.setItem('runOnce', '1');
}
else
{
// The item exists and set!!
// Now we will simulate a click on the about button.
// Which should move the user to your spot with your code.
$('#about-btn').click();
}
});

我建议先学习纯/普通 JS,然后再使用框架来了解一切如何工作的主要思想。

关于javascript - 仅在第一次访问时显示 > if( !localStorage.getItem( "runOnce") ) { 触发 anchor 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23342735/

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