我正在制作一个下拉菜单以放入链接。这些链接强调正确,所以我知道标签正在工作但是当我点击它们时没有任何反应,除非我右键单击并在新标签页中打开。有没有人有建议? 谢谢!
HTML
<div id="dropDown" onmouseover="mouseOver()">\/</div>
的Javascript
function mouseOver()
{
document.getElementById("dropDown").style.height = "150px";
document.getElementById("dropDown").innerHTML = "<a href="https://www.google.ca/">foo</a></br>";
//Other links in list.
}
答案 0 :(得分:1)
这是因为您仍然有onmouseover事件。
试试这个:
<div id="dropDown" onmouseover="mouseOver()">\/</div>
<script>
function mouseOver()
{
document.getElementById('dropDown').setAttribute('onmouseover','');
document.getElementById("dropDown").style.height = "150px";
document.getElementById("dropDown").innerHTML = '<a href="https://www.google.ca/">foo</a></br>';
//Other links in list.
}
</script>
答案 1 :(得分:0)
我认为你的问题在于这行代码;
document.getElementById("dropDown").innerHTML = "<a href="https://www.google.ca/">foo</a></br>";>
尝试改为;
document.getElementById("dropDown").innerHTML = "<a href='https://www.google.ca/'>foo</a></br>";>