gpt4 book ai didi

html - 鼠标进入事件但仅当鼠标进入尚未进入时

转载 作者:行者123 更新时间:2023-11-28 13:28:27 24 4
gpt4 key购买 nike

我有一个 div 元素,我想在鼠标进入时触发一个函数。但它确实位于页面的中心,因此鼠标通常在页面加载和功能运行时位于其上。有没有办法让我的函数在鼠标已经进入但在输入时不运行?

<div id = "mouse-control-div">.....</div>
<script type="text/javascript">
$('#mouse-control-div').mouseover(function() {alert('some thing');});
</script>

我也尝试了 .mouseenter 但结果相同。

(添加了代码示例)

最佳答案

如果您有一个 bool 值来告诉您是否已经输入怎么办?

有关 jQuery 事件的信息:MouseOver/MouseOut 与 MouseEnter/MouseLeave look here

// When the DOM is ready, init scripts.
jQuery(function( $ ){
var isEntered = false;
// Bind the mouse over /out to the first DIV.
$( "#mouse-control-div" ).bind(
"mouseover mouseout",
function( event ){
if(!isEntered)
{
isEntered = true;
echo('entered');
}
}
);

// Bind the mouse enter to the second DIV.
$( "#mouse-control-div" ).bind(
"mouseenter mouseleave",
function( event ){
if(isEntered)
{
isEntered = false;
echo('left');
}
}
);

function echo(string)
{
$('#output').append('<li>'+string+'</li>');
}

});

对于工作演示 look here

关于html - 鼠标进入事件但仅当鼠标进入尚未进入时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13857811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com