gpt4 book ai didi

jquery - 显示类而不是 ID (jQuery)

转载 作者:行者123 更新时间:2023-12-01 06:59:44 24 4
gpt4 key购买 nike

<a href="#tab1">Tab1</a>
<div id="tab1">content</a>
...
var a = $(this).attr('href');
$(a).show();

这有效,但仅当容器具有 ID 时,因为 anchor 链接以“#”开头,我如何使其与类一起工作,以便它识别 <div class="tab1">content</a>

非常感谢

最佳答案

var a = $(this).attr('href');
$(a.replace('#','.')).show();
<小时/>
var a = $(this).attr('href').replace('#','.');
$(a).show();

关于jquery - 显示类而不是 ID (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5062499/

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