我有一个这样的 HTML 页面:
我使用 jquery 在 input.global_filter
上放置了一个事件,如下所示:
$('input.global_filter').on('keyup click', function() {
document.write($(this).find('.example:first').prop('tagName'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Table3-->
<table class="example" data-column="3">
......
</table>
<table>
<tbody>
<tr>
<td>
<input type="text" class="global_filter">
</td>
</tr>
</tbody>
</table>
<!-- Table1-->
<table class="example" data-column="1">
......
</table>
<!-- Table2-->
<table class="example" data-column="2">
......
</table>
这导致 undefined
。它应该给出结果 TABLE
。我哪里错了?
最佳答案
您使用了 parents
而不是 find
。试试这个:
$(function(){
$('input.global_filter').on('keyup click', function() {
console.log($(this).parents().siblings('table').first().prop('tagName'));
console.log($(this).parents().next('.example').data('column'));
});
})
关于jquery - 在我的示例中从 jquery find() 获取未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54939504/