我有这样的链接
<a href="#login_form">Log in</a>点击链接后,网址将从
http:/domain到
domain#login_form,然后弹出一个登录表单. 但我不希望哈希标签显示在url中.如何使用Java脚本执行此操作?没有用于显示弹出的登录表单的Java脚本.
and a login form pops up. But i do not want hash tag to be displayed in url. How to do this using java script? No java script used to display login form which pops up.
登录表单是这样的.
<a href="#x" class="overlay" id="login_form"></a> <div class="box"> <h2>LOG IN</h2> <form name="login" action="" method="post"> </form> </div>好.这是JS FIDDLE.请检查.
OK. HERE IS THE JS FIDDLE. PLEASE CHECK.
jsfiddle/vq24P/1/
推荐答案它被称为文档片段,不是哈希标签,而是什么.
It's called a document fragment, not a hash tag, but whatevs.
如果您说没有Java脚本用于显示登录表单",我只能假设您使用CSS :target伪类来切换可见性?在这种情况下,您无能为力.该片段必须出现在该元素的URL中.
If, as you say, "no java script [is] used to display login form", I can only assume you're using the CSS :target psuedo-class to toggle visibility? In that case, there's nothing you can do. The fragment MUST be in the URL for that element to show up.
相反,请使用一些JavaScript为您进行切换.像这样:
Instead, use some JavaScript to do the toggling for you. Something like:
<a href="javascript:void(document.getElementById('login_form').style.display = 'block');">Log in</a>(警告:极端糟糕的例子,但应该可以使一般想法起作用)
(WARNING: Extremely bad example, but it should get the general idea working)
您将需要使用id="login"而不是name="login"
更多推荐
如何防止片段标识符显示在url中
发布评论