将相同的.click事件应用于两个不同的div [英] applying the same .click event to two different divs
本文介绍了将相同的.click事件应用于两个不同的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个不同的div(代码已简化,这不是实际的代码.)
i have two different divs (code was simplified, this is not the actual code.)
<div id="test"></div>
<div id="funt"></div>
我想要的是,将相同的单击事件附加到#funt
:
像这样:
what i want is, to attach the same click event to #funt
:
something like:
$('#test').click(function() {
DoWork();
});
$('#funt).click(function() {
DoWork();
});
function DoWork(){
alert('yes');
}
但是没有办法定义多个div的相同click事件吗?
but isn't there a way to define multiple div's the same click event?
让我们说(是的,我知道这行不通!)
lets say ( yes, i know this does not work! )
($('#test'),('#funt')).click(function(){alert('yes')});
推荐答案
简单地:
$("#test, #funt").click(DoWork);
请参见多个选择器.
这篇关于将相同的.click事件应用于两个不同的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文