jQuery 当指向链接时应显示默认隐藏的 div

发布于 2024-12-03 02:09:43 字数 509 浏览 0 评论 0原文

我有一个页面,其中默认隐藏了一些 div。我希望能够将用户指向一个显示 div 的链接。

前任。 https://app.emailsmsmarketing.com/login

用户可以点击“注册”来隐藏登录信息div 并显示寄存器 div。我想要完成的基本上是添加一个到主站点的链接,默认情况下用户可以从该站点访问注册表单(仅使用 jQuery)。

前任。 https://app.emailsmsmarketing.com/login#!register (或类似的内容)

基本上我要问的是:

a)可以做到这一点
b) 如果是这样,怎么办?

我不确定这对任何人是否有意义。我很感激所提供的任何帮助。

I have a page where there are a few divs hidden by default. I would like to be able to point users to a link where it would show the divs.

ex. https://app.emailsmsmarketing.com/login

Users are able to click "Register" which hides the login div and shows the register div. What I'm trying to accomplish is basically adding a link to the main site from where users will be able to access the registration form by default (using jQuery only).

ex. https://app.emailsmsmarketing.com/login#!register (or something like that)

Basically what I'm asking is:

a) is is possible to do this
b) if so, how?

I'm not sure if this makes sense to anyone. I appreciate any help provided.

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

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

发布评论

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

评论(3

z祗昰~ 2024-12-10 02:09:44

您可以在 ready 事件期间检查 document.location 属性:

$(document).ready(function() {
  if (document.location.indexOf('#login') > -1)
    $("#login").show();
});

You can examine the document.location property during ready event:

$(document).ready(function() {
  if (document.location.indexOf('#login') > -1)
    $("#login").show();
});
如若梦似彩虹 2024-12-10 02:09:44

您可能正在寻找这个:基于锚点的 URL 导航使用 jQuery

var myUrl = document.location.toString();
if (myUrl.match('#')) { // the URL contains an anchor

  var myAnchor = '#' + myUrl.split('#')[1];
  $('#login').hide();
  $('#register').show();
}

You probably looking for this: Anchor-based URL navigation with jQuery

var myUrl = document.location.toString();
if (myUrl.match('#')) { // the URL contains an anchor

  var myAnchor = '#' + myUrl.split('#')[1];
  $('#login').hide();
  $('#register').show();
}
冰魂雪魄 2024-12-10 02:09:44

当然,只需在链接上设置一个类或 id 或其他内容,如下所示:

<a href="#" class="register"> Register! </a>

然后在 jQuery 中执行此操作

$("a.register").click(function() { 
    $("#logindiv").hide()
    $("#registerdiv").show();
    return false; // prevents the default behavior of the link, ie following it
});

其中 registerdiv 是隐藏 div 等的 ID。

Well sure, just set a class or id or something on your link, like so:

<a href="#" class="register"> Register! </a>

Then do this in jQuery

$("a.register").click(function() { 
    $("#logindiv").hide()
    $("#registerdiv").show();
    return false; // prevents the default behavior of the link, ie following it
});

Where registerdiv is the ID of your hidden div etc.

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