<li> 的 jQuery onclick 事件标签 [英] jQuery onclick event for <li> tags
本文介绍了<li> 的 jQuery onclick 事件标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下菜单项由模板生成器,artisteer 生成:
I have the following menu items generated by a template generator, artisteer:
<ul class="art-vmenu">
<li><a href="#" ><span class="l"></span><span class="r"></span>
<span class="t">Home</span></a></li>
<li><a href="#" ><span class="l"></span><span class="r"></span>
<span class="t">Create User</span></a></li>
<li><a href="#" class="active"><span class="l"></span><span class="r"></span>
<span class="t">List Users</span></a></li>
<li><a href="#"><span class="l"></span><span class="r"></span>
<span class="t">Admin</span></a></li>
</ul>
我想用一个 jQuery 函数捕获 的 onclick 事件:我试过这个是不完整的:
I want to capture the onclick event for <li>
with a single jQuery function:
I've tried this which is incomplete:
$(document).ready(function()
{
$('ul.art-vmenu li').click(function(e)
{
alert(this);
});
});
我可以看到这是一个 HTMLliElement,但不知道如何获取它的菜单文本或 id?
I can go as far as seeing this is a HTMLliElement but cannot figure how to get the menu text or id for it?
通常如何使用 jQuery 捕获菜单点击?
How is menu click usually captured with jQuery?
推荐答案
这里,获取触发事件的菜单文本(好像没有任何id):
Here, to get the text of the menu that triggered the event (does not seem to have any id):
$(document).ready(function()
{
$('ul.art-vmenu li').click(function(e)
{
alert($(this).find("span.t").text());
});
});
这篇关于<li> 的 jQuery onclick 事件标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文