比方说,我有一个位于一个隐藏的div(display:none
)这里面的内在联系 - 一个按钮被点击时的div切换:显示的链接是一个隐藏的DIV中
<a name="here">Show me!</a>
我怎样才能让元素可见当有人输入网址:mypageurl#这里,没有点击切换按钮(默认情况下,当这个特定的链接输入时显示)?
比方说,我有一个位于一个隐藏的div(display:none
)这里面的内在联系 - 一个按钮被点击时的div切换:显示的链接是一个隐藏的DIV中
<a name="here">Show me!</a>
我怎样才能让元素可见当有人输入网址:mypageurl#这里,没有点击切换按钮(默认情况下,当这个特定的链接输入时显示)?
$().ready(function() {
var hash = $.trim(window.location.hash);
if (hash != '') {
var prt = $('[name="' + hash.substr(1) + '"]').parent();
prt.show();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="display:none;"><a name="here">Show me!</a></div>
全部代码!
您可以使用CSS“visibility:hidden”,然后在有人输入特定短语时使用JavaScript将其更改为“visibility:visible”。
或者,您可以使用display:“”;或者在发生同样的操作时在“display:none”div上显示:block,再次使用一些JavaScript。
您可以使用下面的脚本。
<script>
$(document).ready(function(){
var loc = document.location.hash;
if(loc == "#test")
{
$('#test').show();
}
});
</script>
下面是一个简单的页面的源代码,我提出:
<html>
<script src="http://code.jquery.com/jquery-latest.min.js "></script>
<body>
<div id="hide" style="display:none">
<a name="here">Show me!</a>
</div>
</body>
<script>
$(document).ready(function(){
if(document.location.href.search("#hide")>0){
$("#hide").toggle();
}
});
</script>
</html>
它会显示DIV与IDhide
网页中是否有文字"#hide"
,否则它一直隐藏。
你可以检查document.ready上的页面的url,并编写代码来显示div,如果url包含你想要的#ref – inquizitive