假设我们有一个像这样的基本列表:
<ul id="list">
<li></li>
<li></li>
<li></li>
</ul>
$('#list').on('click', function() {
// how to get the li element that was clicked within the ul element?
});
最佳答案
这很简单:
$('#list').on('click','li', function() {
// how to get the li element that was clicked within the ul element?
});
通过将选择器添加为 .on() 方法的额外参数,您可以访问触发事件的元素。
关于JQuery:在单击的父项的光标下获取子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9941449/