admin管理员组文章数量:1336660
I have bined function like this(simplified version):
$('label').bind('click hover', function() {
$('label').removeClass("active");
$(this).addClass("active");
});
How can I add an if
to check if it is a click?
I have bined function like this(simplified version):
$('label').bind('click hover', function() {
$('label').removeClass("active");
$(this).addClass("active");
});
How can I add an if
to check if it is a click?
1 Answer
Reset to default 8Use event.type
:
$('label').bind('click hover', function(event) {
if(event.type == 'click') {
// do stuff
}
$('label').removeClass("active");
$(this).addClass("active");
});
Demo: http://jsfiddle/jtbowden/sqvDy/
Note, the demo uses .on()
, which is the new method of event binding for jQuery 1.7+, replacing .bind()
, .live()
, and .delegate()
.
本文标签: javascriptJquery bind click and hoverhow to check if clickStack Overflow
版权声明:本文标题:javascript - Jquery bind click and hover, how to check if click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742420905a2471633.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论