Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这应该很容易,但我在网上找不到太多:
我有一个无序列表<ul>,下面有一些列表项<li>,我想解决列表中的每一项,并采取行动。如何使用 jQuery 做到这一点?
<ul>
<li>
谢谢。
您可以为此使用each()。
例如
$('ul#id li').each(function(index, element) { var li = $(element); // ... });
接近这个的东西:
$('#myulid').children('li').each(function(i, n) { alert($(this).html()); });
使用此代码并根据需要更改 id。
$("ul#id_of_desired_ul > li").each(function() { //do stuff // $(this) references each li });