HTML :
<div class="hover">hover</div>
<div class="click">click</div>jQuery :
$('.hover').hover(function(){
alert("hovered!");
});
$('.click').click(function(){
$('.hover').hover();
});这段代码不起作用,但我可以喜欢$('.hover').hover()吗?
游乐场: http://jsfiddle.net/wbFLH/
PS :我知道我可以像那样
$('.hover').hover(function(){
func();
});
$('.click').click(function(){
func();
});
function func() {
alert("something")
}但是我想知道,我可以通过使用“单击”函数来悬停和调用悬停函数吗?
发布于 2013-05-06 13:25:39
.hover()使用.mouseenter()和.mouseleave(),因此必须触发.mouseenter/.mouseleave。
来自jQuery .hover docs
.hover()方法为mouseenter和mouseleave事件绑定处理程序。您可以使用它简单地将行为应用到元素中,鼠标在元素中的时间。 调用$(selector).hover(handlerIn,handlerOut)是以下的缩写: $(selector).mouseenter(handlerIn).mouseleave(handlerOut);
$('.hover').hover(function(){
$('code').append('l');
});
$('.click').click(function(){
$('.hover').mouseenter();
});EXAMPLE
https://stackoverflow.com/questions/16399727
复制相似问题