JavaScript-跳转到锚点
我正试着跳到锚地开始跳水。开口部分正在工作,但没有跳到指定的锚 这是我的剧本:JavaScript-跳转到锚点,javascript,anchor,Javascript,Anchor,我正试着跳到锚地开始跳水。开口部分正在工作,但没有跳到指定的锚 这是我的剧本: <script type="text/javascript"> function spoil(id){ if (document.getElementById) { var divid = document.getElementById(id); divid.style.display = (divid.style.display =
<script type="text/javascript">
function spoil(id){
if (document.getElementById) {
var divid = document.getElementById(id);
divid.style.display = (divid.style.display = 'block');
window.location = '#' + id;
}
}
</script>
<a href="http://example.com" onclick="spoil('thanks');" title="hello">
<img src="images/gfx.png" alt="world" width="300" height="300"/>
</a>
功能(id){
if(document.getElementById){
var divid=document.getElementById(id);
divid.style.display=(divid.style.display='block');
window.location='#'+id;
}
}
你知道有什么问题吗?
干杯。您是否尝试过
window.location.hash='#'+id代码>?看起来您正在取消隐藏扰流板div。如果是这样,您可以按如下方式将元素滚动到视图中:
function spoil(id) {
var divid = document.getElementById(id);
divid.style.display = 'block';
divid.scrollIntoView(true);
return false;
}
...
<a href="#" onclick="return spoil('thanks');" title="hello"><img src="images/gfx.png" alt="world" width="300" height="300"/></a>
功能破坏(id){
var divid=document.getElementById(id);
divid.style.display='block';
divid.scrollIntoView(true);
返回false;
}
...