我在下面的标记中显示子菜单
<ul class="list-unstyled collapse show" id="pageSubmenu" style="">
<li><a href="">Report 1</a></li>
<li><a href="">Report 2</a></li>
<li><a href=""> Report 3</a></li>
</ul>
处理点击事件的jQuery如下
$("#pageSubmenu li a").click(function () {
$(this).children('a').trigger('click');
alert('clicked');
});
我的代码有什么问题?
答案 0 :(得分:2)
$("#pageSubmenu li a").click(function () {
alert($(this).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="list-unstyled collapse show" id="pageSubmenu" style="">
<li><a href="#">Report 1</a></li>
<li><a href="#">Report 2</a></li>
<li><a href="#">Report 3</a></li>
</ul>