我有一个带有链接的 div,当您将鼠标悬停在链接上时,它们会带有下划线。我向 div 添加了一个 onmouseover
JS 事件,现在当我将鼠标悬停在超链接上时,超链接不再带有下划线,而是执行我放入 onmouseover
事件中的任何操作。
函数代码:
function addPlus(elementId)
{
if(typeof addPlus.backup == 'undefined')
addPlus.backup = document.getElementById(elementId).innerHTML;
if(full)
{
document.getElementById(elementId).innerHTML = plusCode + addPlus.backup;
return backup;
}
else
return snippet;
}
div 代码:
<div class="nav_bar" id="navbar1" onmouseover="addPlus('navbar1')" onmouseout="removePlus('navbar1')">
编辑:我尝试过 return true;
、return Boolean(true);
,并return new Boolean(true);
,试图按照 Chad 的建议“返回 true”。它们都不起作用。抱歉,我真的不知道该怎么办;我是 JavaScript 新手。
编辑2:该死的,我刚刚意识到Chad意味着我在div标签中返回true。所以现在我有
,但不幸的是它仍然不起作用。
I had a div with links that underlined once you hover over them. I added an onmouseover
JS event to the div and now the hyperlinks no longer underline when I hover over them, but instead whatever action I put into the onmouseover
event gets executed instead.
CODE from function:
function addPlus(elementId)
{
if(typeof addPlus.backup == 'undefined')
addPlus.backup = document.getElementById(elementId).innerHTML;
if(full)
{
document.getElementById(elementId).innerHTML = plusCode + addPlus.backup;
return backup;
}
else
return snippet;
}
div code:
<div class="nav_bar" id="navbar1" onmouseover="addPlus('navbar1')" onmouseout="removePlus('navbar1')">
EDIT: I've tried return true;
, return Boolean(true);
, and return new Boolean(true);
, in an attempt to "return true" as Chad suggested. None of them work. Sorry, I really don't know what to do; I'm new to Javascript.
EDIT 2: Darn it, I just realized Chad meant that I return true in the div tag. So now I have <div class="nav_bar" id="navbar1" onmouseover="addPlus('navbar1');return true" onmouseout="removePlus('navbar1')">
, but it unfortunately still doesn't work.
发布评论
评论(3)
为了使事件传播,您需要从 onmouseover 处理程序返回 true。
for the event to propagate you need to return true from your onmouseover handler.
onmouseover
处理程序来处理链接下划线(而不是正确使用addEventListener
),然后您将覆盖此处理程序。如果没有更多信息,很难猜测可能出了什么问题。提供代码示例以获得更多帮助。onmouseover
handler in HTML or JavaScript to handle the link underline (instead of properly usingaddEventListener
), and then you are overwriting this handler. It's hard to guess what might be wrong without more information. Supply a code example for more help.如果您不希望触发 js 事件,则应该在鼠标进入
时停止事件传播。尝试为每个超链接添加 onmouseover 事件处理程序并返回 false -
- 这应该会有所帮助。
If you don't want for js event to fire you should stop event propogation when mouse enters
<a>
. Try adding onmouseover event handler for each hyperlink with return false -<a onmouseover="return false" ...
- that should help.