jquery 单独切换

发布于 2024-10-06 07:14:38 字数 890 浏览 0 评论 0原文

我的 html 是这样的:

<a class="tableheadlink" href="#">Impressions</a> <a href="#"><img src="images/table-sort.png" alt="" /></a>
<div class="filter-head">
    <form>
        <select name="website" class="rounded-all no-padding">
            <option value="opt1">&gt;</option>
            <option value="opt2">&lt;</option>
            <option value="opt3">=</option>
        </select>
        <input name="q" type="text" class="rounded-all small">
    </form>
</div>

jquery 是这样的:

        $(".filter-head").hide();
        $("a.tableheadlink").click(function(){
            $(".filter-head").toggle();
            return false;
        });

我如何告诉它单独切换 html 部分的每个瞬间?页面上大约有 10 个实例,切换将使用我的代码切换所有实例。

谢谢

My html is something like this:

<a class="tableheadlink" href="#">Impressions</a> <a href="#"><img src="images/table-sort.png" alt="" /></a>
<div class="filter-head">
    <form>
        <select name="website" class="rounded-all no-padding">
            <option value="opt1">></option>
            <option value="opt2"><</option>
            <option value="opt3">=</option>
        </select>
        <input name="q" type="text" class="rounded-all small">
    </form>
</div>

jquery something like this:

        $(".filter-head").hide();
        $("a.tableheadlink").click(function(){
            $(".filter-head").toggle();
            return false;
        });

How do i tell it to toggle each instant of the html section individually? There is about 10 instances of it on the page and the toggle will just toggle all using my code.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-10-13 07:14:38

您需要找到您想要的 相对< /a> 到 this,例如:

$(".filter-head").hide();
$("a.tableheadlink").click(function(){
    $(this).nextAll(".filter-head:first").toggle();
    return false;
});

this 的作用是从 this 然后使用 .nextAll() 与您的类选择器并获取 :first 遇到要切换的一个。 .nextAll() 而不是 .next() 是中间有其他链接。

You need to find the .filter-head you want relative to this, for example:

$(".filter-head").hide();
$("a.tableheadlink").click(function(){
    $(this).nextAll(".filter-head:first").toggle();
    return false;
});

What this does is go from this then uses .nextAll() with your class selector and gets the :first one it encounters to toggle. The reason for .nextAll() instead of .next() is that there is that other link in-between.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文