使用 jQuery 隐藏锚点

发布于 2024-10-15 02:06:42 字数 1530 浏览 1 评论 0原文

我创建了一个动态页面,根据视图类型,有时会使用锚标记,有时则不会。本质上,我希望能够控制单击页面是否跳转到锚点。是否可以使用 jQUery 隐藏锚标记,从而基本上将其删除?我需要能够在必要时重新启用锚点,并始终在浏览器的地址栏中显示当前锚点。它似乎可以在 FireFox 中运行,但不能在 Internet Explorer 中运行。

我有三个部分:“目录”、内容和 javascript (jQuery) 代码

目录

<a id="expandLink0" class="expandLinksList" href="#green">What is green purchasing</a><br>
<a id="expandLink1" class="expandLinksList" href="#before">Before you buy</a><br>

内容

<ul id="makeIntoSlideshowUL">'
<li id="slideNumber0" class="slideShowSlide">
    <a name="green"></a>
    <div>Green Purchasing refers to the procurement of products and service...<a href="#topOfPageAnchor" class="topOfPageAnchorClass">Back to Top</a></div>
</li>
<li id="slideNumber1" class="slideShowSlide">
    <a name="before"></a>
    <div>We easily accomplish the first four bullet points under...<a href="#topOfPageAnchor" class="topOfPageAnchorClass">Back to Top</a></div>
</li>
</ul>

页面加载时的 jQuery

$(".slideShowSlide").each(function() {
$(this).children(":first-child").hide();
});

jQuery 重新启用链接

$(".slideShowSlide").each(function() {
$(this).children(":first-child").show();
});

我还尝试在所有锚点名称前面添加一个额外的字符以“禁用”它们,但 IE 不会使用 attr("name") 更改名称。它允许我做的唯一真正的操作是remove()。

I've created a dynamic page that, depending on the view type, will sometimes utilize the anchor tags and other times not. Essentially, I want to be able to control if on click the page jumps to the anchor. Is it possible to hide anchor tags using jQUery, so they are essentially removed? I need to be able to re-enable the anchors when necessary, and always show the current anchor in the browser's address bar. It seems to work in FireFox, but not in Internet Explorer.

I have three sections: the 'table of contents', the content, and the javascript (jQuery) code

Table of Contents

<a id="expandLink0" class="expandLinksList" href="#green">What is green purchasing</a><br>
<a id="expandLink1" class="expandLinksList" href="#before">Before you buy</a><br>

Contents

<ul id="makeIntoSlideshowUL">'
<li id="slideNumber0" class="slideShowSlide">
    <a name="green"></a>
    <div>Green Purchasing refers to the procurement of products and service...<a href="#topOfPageAnchor" class="topOfPageAnchorClass">Back to Top</a></div>
</li>
<li id="slideNumber1" class="slideShowSlide">
    <a name="before"></a>
    <div>We easily accomplish the first four bullet points under...<a href="#topOfPageAnchor" class="topOfPageAnchorClass">Back to Top</a></div>
</li>
</ul>

jQuery On Page Load

$(".slideShowSlide").each(function() {
$(this).children(":first-child").hide();
});

jQuery to re-enable links

$(".slideShowSlide").each(function() {
$(this).children(":first-child").show();
});

I've also tried prepending an extra character to all anchor names to 'disable' them, but IE won't change the names using attr("name"). The only real manipulation it's letting me do is remove().

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

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

发布评论

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

评论(1

装迷糊 2024-10-22 02:06:42

尝试这样做:

$(".slideShowSlide").each(function() {
    $(this).children().first().hide();
});

甚至这样:

$(".slideShowSlide").each(function() {
    $(this).children(':first').hide();
});

Try doing it this way:

$(".slideShowSlide").each(function() {
    $(this).children().first().hide();
});

Or even this way:

$(".slideShowSlide").each(function() {
    $(this).children(':first').hide();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文