检查已使用jQuery单击的元素 [英] Check which element has been clicked with jQuery
本文介绍了检查已使用jQuery单击的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用'if'语句来确定单击了哪个元素.
I am trying to use an 'if' statement to determine which element was clicked.
基本上,我正在尝试按照以下方式编写代码:
Basically I am trying to code something along the lines of:
if (the element clicked is '#news_gallery li .over') {
var article = $('#news-article .news-article');
} else if (the element clicked is '#work_gallery li .over') {
var article = $('#work-article .work-article');
} else if (the element clicked is '#search-item li') {
var article = $('#search-item .search-article');
};
正确的jQuery语法是什么?预先非常感谢.
What is the proper jQuery syntax for this? Many thanks in advance.
推荐答案
使用它,我想我可以理解你的想法.
Use this, I think I can get your idea.
实时演示: http://jsfiddle.net/oscarj24/h722g /1/
$('body').click(function(e) {
var target = $(e.target), article;
if (target.is('#news_gallery li .over')) {
article = $('#news-article .news-article');
} else if (target.is('#work_gallery li .over')) {
article = $('#work-article .work-article');
} else if (target.is('#search-item li')) {
article = $('#search-item .search-article');
}
if (article) {
// Do Something
}
});
这篇关于检查已使用jQuery单击的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文