用于跨度内跨度的 CSS 或 jQuery 选择器
我正在尝试使用纯 CSS 或 JQuery 选择器在 div 内的跨度内选择一个跨度。 html 如下:
<div id="example2_paginate" class="dataTables_paginate paging_full_numbers">
<span id="example2_first" class="first paginate_button paginate_button_disabled">First</span>
<span id="example2_previous" class="previous paginate_button paginate_button_disabled">Previous</span>
<span>
<span class="paginate_active">1</span>
<span class="paginate_button">2</span>
<span class="paginate_button">3</span>
<span class="paginate_button">4</span>
<span class="paginate_button">5</span>
</span>
<span id="example2_next" class="next paginate_button">Next</span>
<span id="example2_last" class="last paginate_button">Last</span>
</div>
我想选择包含 1 到 5(paginate_active 和 5 个分页按钮)的跨度,单独。
由于我对 CSS 和 jQuery 的了解非常有限,我尝试了几种但我确信我的语法是错误的,例如 $("paging_full_numbers span:eq(1)")
。
您能否给我一个提示,告诉我如何去做?
I am trying to select a span within a span within a div using plain CSS or JQuery selectors. The html is as follows:
<div id="example2_paginate" class="dataTables_paginate paging_full_numbers">
<span id="example2_first" class="first paginate_button paginate_button_disabled">First</span>
<span id="example2_previous" class="previous paginate_button paginate_button_disabled">Previous</span>
<span>
<span class="paginate_active">1</span>
<span class="paginate_button">2</span>
<span class="paginate_button">3</span>
<span class="paginate_button">4</span>
<span class="paginate_button">5</span>
</span>
<span id="example2_next" class="next paginate_button">Next</span>
<span id="example2_last" class="last paginate_button">Last</span>
</div>
I want to select spans that contain 1 to 5 (paginate_active and the 5 paginate buttons), individually.
With my very limited knowledge of CSS and jQuery I've tried a couple of things but I'm sure my syntax is wrong, like $("paging_full_numbers span:eq(1)")
.
Could you please give me a hint of how to go about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要单独选择它们,您可以简单地选择它们,然后使用 jQuerys
.each()
。例如spanList = $('#example2_paginate').find('.paginate_active, .paginate_button');
将查找 id 元素内的所有 'paginate_active' 或 'paginate_button' 类= example2_paginate。然后你可以写:
或者选择第 i 个按钮而不循环遍历所有按钮:
参见 jsFiddle:http://jsfiddle。净/t4KWr/
To select them individually, you can simply select them all and then use jQuerys
.each()
. For examplespanList = $('#example2_paginate').find('.paginate_active, .paginate_button');
will find all classes of 'paginate_active' or 'paginate_button' that, are inside your element of id=example2_paginate. Then you can write:
Alternatively to select the i^th button without looping through them all:
See jsFiddle: http://jsfiddle.net/t4KWr/
这个CSS就是你想要的。
This CSS is what you want.
例如,获取 5 个跨度中的第三个的快速方法是:
A quick way to get, say, the third of the 5 spans would be:
似乎有一个问题
You should write like
或者 if you are using class
its seem that there is a problem with
You should write like
Or if you are using class
此选择包含 1 到 5 个范围(paginate_active 和 5 个分页按钮)的范围,分别:
选择仅包含“paginate_active”类或仅包含“paginate_button”类的范围
This select spans that contain 1 to 5 (paginate_active and the 5 paginate buttons), individually:
That select the span's with only class 'paginate_active' or only class 'paginate_button'