同时发生两个事件 [英] Two events at the same time

查看:91
本文介绍了同时发生两个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击类.smth时,我想做一些动作

I want to do some actions when class .smth is clicked

$('.smth').click(function() {

以及按下键时:

$('.txt').bind('keypress', function(e) {

我想执行相同的操作,那么如何将它们与OR或类似的东西一起使用?

I want to do the same action, so how can I use them both with OR or something like that?

$('.log').click.or.$('.txt').bind('keypress', function(e) {

?

谢谢你.

推荐答案

如果这是相同的元素集合,则可以使用:

If this was the same collection of elements you could use:

$(".myclass").bind("click keypress", function(event) {
    //...
});

但是由于元素不同,您必须遵循Felix的建议并编写一个函数,然后将其附加为事件处理程序.

But as it's different elements you'll have to follow Felix advice and write a function then attach it as the event handler.

这篇关于同时发生两个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆