<分区>
使用jQuery
console.log($(this).html());
console.log($(this).data('section'));
产量
<a href="#" data-section="allothers" data-sectiontitle="Other Information" style="font-weight: 600; text-decoration: none;">Include Children?</a>
和
undefined
而且我不确定我做错了什么。 <a>
这是一个未排序的列表 <li>
标签,但我不确定为什么这很重要。提前致谢!
如你所说,它是<li>
附上 <a>
那么应该是:-
console.log($('li a').html());
console.log($('li a').data('section'));
例子:-
console.log($('li a').html());
console.log($('li a').data('section'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a href="#" data-section="allothers" data-sectiontitle="Other Information" style="font-weight: 600; text-decoration: none;">Include Children?</a></li>
注意:- 你可以做 $(this).find('a').data('section');
也基于您的 HTML 结构。