![](/img/trans.png)
[英]Javascript: "Mouseover" and "mouseout" event handlers work, but "mouseout" doesn't work properly when "mouseover" is replaced by "click"
[英]JavaScript: DRY mouseover/mouseout event handlers
这是我的代码:
$rows
.on('mouseover', '.row', function () {
$(this).find('.label').show();
})
.on('mouseout', '.row', function () {
$(this).find('.label').hide();
});
可以晾干吗?
您可以绑定两个事件,侦听event.name
,然后使用jQuery.fn.toggle
$userRows.on('mouseover mouseout', '.row', function(event) {
$(this).find(".label").toggle( event.name == "mouseover" );
});
我很确定你也可以使用jQuery.fn.hover :
$userRows.on('hover', '.row', function(event) {
$(this).find(".label").toggle( event.name == "mouseenter" );
});
甚至:
$userRows.on('hover', '.row', function(event) {
$(this).find(".label").toggle();
});
关于什么:
$ rows.hover(function(){$(this).find('。label')。toggle();},function(){$(this).find('。label')。toggle();} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.