-1

我有一个 div 和一个链接。因此,当我单击链接时,它应该向我显示 div。但现在的问题是,我只看到 div 一秒钟,然后 div 再次隐藏。

为什么?

...
<div id = 'zuordnen'>
    test
</div>

...

echo "<a href = '' ><img src = './images/zuordnen_menu.png' border=0 style =' width:1vw; height: 2vh;' onClick = 'showzuordnen();'></a>&nbsp;&nbsp;&nbsp;";

JAVASCRIPT:

function showzuordnen()
{
    document.getElementById("zuordnen").style.visibility = "visible";
}

CSS:

#zuordnen {
    z-index: 1;
    position: absolute;
    width: 20px;
    height: 6vh;
    border: 1px solid #ff0000;
    left: 20px;
    visibility: hidden;
}
4

1 回答 1

1

正如j0869指出的那样,问题是每次单击图像时都会刷新页面,因为图像位于标记内。
要解决这个问题,只需删除包装图像的锚标记 ( <a>)。

看看代码笔看看它的工作原理:http ://codepen.io/HywelMartin/pen/BjBxaj


如果您真的需要锚标签,只需href=''href='#'.

于 2015-12-02T20:07:44.127 回答