admin管理员组文章数量:1221774
I have a script that makes the element display = block using onmouseover
<script language="JavaScript">
function aaa()
{
document.getElementById('cat').style.display = "block";
}
</script>
<a href='#' onmouseover='aaa()'>hover on me</a>
<div id='cat' style='display:none;'>this will show</div>
I wanted to return that element back to it's original display properties (none) when the mouse isn't over the
"<a href='#' onmouseover='aaa()'>hover on me</a>"
how can I do this?
I have a script that makes the element display = block using onmouseover
<script language="JavaScript">
function aaa()
{
document.getElementById('cat').style.display = "block";
}
</script>
<a href='#' onmouseover='aaa()'>hover on me</a>
<div id='cat' style='display:none;'>this will show</div>
I wanted to return that element back to it's original display properties (none) when the mouse isn't over the
"<a href='#' onmouseover='aaa()'>hover on me</a>"
how can I do this?
Share Improve this question edited Sep 5, 2012 at 6:31 Danil Speransky 30.5k6 gold badges69 silver badges78 bronze badges asked Sep 5, 2012 at 5:59 Sam SanSam San 6,9039 gold badges35 silver badges51 bronze badges 1- Next time, google it before ask. – totten Commented Sep 5, 2012 at 6:08
5 Answers
Reset to default 7There's the onmouseout
event
function bbb()
{
document.getElementById('cat').style.display = "none";
}
...
<a href='#' onmouseover='aaa()' onmouseout='bbb()'>hover on me</a>
Demo: http://jsfiddle.net/TRxRV/1/
HTML:
<a href='#' onmouseover='show();' onmouseout='hide();'>hover</a>
<div id='cat' style='display:none;'>cat</div>
JavaScript:
window.show = function () {
document.getElementById('cat').style.display = "block";
}
window.hide = function () {
document.getElementById('cat').style.display = "none";
}
i am considering the same code u provided as example. If u include the original display properties within the onMouseout() Function U will get back to the original properties when the mouse is not over.
<script language="JavaScript">
function aaa()
{
document.getElementById('cat').style.display = "block";
}
function bbb()
{
//include the code TO CHAGE THE PROPERTY HERE
document.getElementById('cat').style.display = " ";
}
</script>
<a href='#' onmouseover='aaa();' onmouseout="bbb();">hover on me</a>
<div id='cat' style='display:none;'>this will show</div>
This should help you...
function aaa()
{
document.getElementById('cat').style.display = "block";
}
function bbb()
{
document.getElementById('cat').style.display = "none";
}
<a href='#' onmouseover='aaa()' onmouseout="bbb();">hover on me</a>
<div id='cat' style='display: none;'>this will show</div>
You should use onMouseOut
event for that, code will look like
<a href='#' onmouseover='show();' onmouseout='dontShow();'>hover</a>
<div id='cat' style='display:none;'>this will show</div>
function show() {
document.getElementById('cat').style.display = "block";
}
function dontShow() {
document.getElementById('cat').style.display = "none";
}
本文标签: htmljavascriptHow to detect if not onmouseoverStack Overflow
版权声明:本文标题:html - javascript - How to detect if not onmouseover? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739347362a2159224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论