0

it making me crazy, i'm probably stupid :)

Go to this link : http://www.willbegood.com/lab/whatup/list2.php?categ=4

Why to this page return "1", it should be return "4". There are 4 div whith the id equal to "liste-item", why it return only 1? My page is generated by a simple php query, is this the reason?

I have also tryed to test this with the same page but static (html) : same problem Check here : http://www.willbegood.com/lab/whatup/list3.html

Thanks

4

4 回答 4

1

You are only allowed one id element. That's probably why. Change it to class.

于 2012-12-06T20:47:49.807 回答
1

You cannot duplicate ID. ID should be unique in a DOM and the jQuery selector would return only 1 which is the first element with liste-item.

Use class instead of ID.

于 2012-12-06T20:47:53.013 回答
1

页面中的IDHTML应该是唯一的。

如果您按ID选择它,它将返回 ID 的第一次出现 它不会再看下去了。

在这种情况下,最好将其替换为class.

替换id="liste-item" class="liste-item"

于 2012-12-06T20:48:05.217 回答
1

您的问题是您在需要使用类的地方使用 id。根据定义,ID 必须是唯一的。当您在 jquery(或直接 JS)中按 Id 选择时,您只会得到一个元素。将您的 div 更改为

<div class='liste-item off'></div>
<div class='liste-item off'></div>
<div class='liste-item off'></div>
<div class='liste-item off'></div>

alert($(".liste-item").length) 可以在这里找到关于 id 和 class 选择器的 JS 教程:http: //www.htmldog.com/guides/cssintermediate/classid/

于 2012-12-06T20:50:19.710 回答