在此示例中如何访问外部选择器 [英] how to access outside selector in this example
本文介绍了在此示例中如何访问外部选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下标记:
<div class='header-vals' data-item-id='23'>
<input type='text' name='some-input' />
<input type='text' name='some-other-input' />
</div>
,并希望ot可以通过以下方式访问data-item-id(但这不起作用):
and would like ot access the data-item-id with something like this (but this doesn't work):
$('.header-vals').on('keyup','input',function(){
var item_id=$(this).data('item-id');
});
有没有一种方法可以使这个参考到外面,以便我可以获取data-item-id?
Is there a way to make the reference of this to the outside so that I can get the data-item-id?
提前谢谢
推荐答案
这样做:-
$('.header-vals').on('keyup','input',function(){
alert($(this).parent().attr('data-item-id'));
});
引用 实时演示
Refer LIVE DEMO
这篇关于在此示例中如何访问外部选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文