获取元素的`id`属性 [英] Getting an element's `id` attribute
本文介绍了获取元素的`id`属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能使用jQuery获得html标签的 id
属性吗?
Can you get the id
attribute of a html tag using jQuery or without?
例如:
<ul id="todo" />
如何获得 id
,使用 jQuery(#todo)
?
有没有办法呢?将 attr()
工作?
Is there a way for that? Will attr()
work?
推荐答案
我看到的方式,你很可能需要将一个选择器类附加到 ul ,以便你可以用它来获取id:
The way I see it, you most probably need to attach a selector class to the ul so that you can use it to get the id:
<ul id="todo" class="todoclassname" />
然后,您可以通过以下方式获取ID:
then, you can get the id by doing:
$(".todoclassname").attr("id");
这篇关于获取元素的`id`属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文